This post was first published on Setting Up Your Own Git Server
Setting up your own git server is very useful. You can set up your own git server on Vps, Vds, Dedicated servers or even on your local machine. I assume you have installed git on your Linux server.
First we need to create a git directory under the root directory. In the following code I will create a example named git server. So you can set up as many git servers as you like.
Then in the terminal, go to the directory /git/example.git and write the following code.
git init --bare
That’s all!! We created our git server. If you want to clone you should write the following code;
git clone username@serveripaddress:/git/example.git
It will ask your server’s password.
If you have a local project on your computer and you want to include it in your git server, type the following code in the terminal under your project directory;
git remote add myserver username@serveripaddress:/git/example.git git push myserver -u master
You can change “myserver” with a name whatever you want. “origin” is commonly used name.
When you send your commits with the push command, your server will ask for the user password.
If you want your server to take your commits and create your project in another directory when you send your commits, you must create a post-recived named file under the /git/example.git/hooks directory with 777 permission. why would you want such a thing? In your project, we assume that you have commands that do build operations like gulp. After sending your commits, you can want that your gulp processes run automatically and the your project will be ready. You can even have development and production branches run automatically in separate folders.
Edit the inside of post-recived file as follows.
#!/bin/bash GIT_WORK_TREE=/home/project-directory/ git checkout -f master
You can set the directory location as you like.
If you are using something like composer, bower, you can arrange them to work as follows.
#!/bin/bash GIT_WORK_TREE=/home/project-directory/ git checkout -f master cd /home/project-directory/ php composer.phar update cd /home/project-directory/ bower install
Learning to code products doesn't take as long as you think - more precisely, 300 hours to learn, build, and launch. Learn about the history and misconceptions of development preventing you from even starting and then hop on that tech bus.