Setting up Git HTTP Backend for local collaboration
You want to share a topic branch with a colleague but do not want to push that branch upstream to Github/BitBucket/GitLab, etc. How do you do this? You could create a patch and email it. Or you could do it in the most crazy way possible and use Apache and allow your colleague to pull from your repo directly. This does take a bit more time to setup, but it would also be absolutely crazy dumb for everyone involved. Basically, let's setup a git server on your workstation!
First create a place to store your repos. Let's also create a test repo to work with to make sure everything is working.
mkdir -p ~/Sites/git cd ~/Sites/git mkdir testproject.git cd testproject.git git init --bare
Next let's setup Apache (I am using OS X El Capitan with Apache 2.4).
Ensure the following modules are being loaded.
LoadModule cgi_module libexec/apache2/mod_cgi.so LoadModule env_module libexec/apache2/mod_env.so
Uncomment the following line:
I removed the existing virtualhosts since I actually do all of my development with Vagrant and Linux. So I really have no need to have anything more than a single virtualhost on my Mac.
<VirtualHost *:80> DocumentRoot /Users/user/Sites <Directory "/Users/user/Sites/"> Options +Indexes +MultiViews +FollowSymLinks +ExecCGI AllowOverride All Require all granted </Directory> <Directory "/Library/Developer/CommandLineTools/usr/libexec/git-core/"> Options +ExecCGI Require all granted </Directory> <LocationMatch "^/git/"> Require all granted </LocationMatch> SetEnv GIT_PROJECT_ROOT /Users/user/Sites/git SetEnv GIT_HTTP_EXPORT_ALL SetEnv REMOTE_USER user ScriptAlias /git/ /Library/Developer/CommandLineTools/usr/libexec/git-core/git-http-backend/ </VirtualHost>
Edit the the bolded parts to suit your local setup.
sudo apachectl restart
Your git repos will now be available at http://locahost/git/<REPONAME.git>.
You should now be able to clone your empty repo.
Let's test it out.
You should be able to make changes and push to your remote.
cd ~/Sites git clone http://localhost/git/testproject.git testproject cd testproject
echo '# README' > README.me git add README.md git commit -am 'Add Readme' git push origin master
There it is!
Now you can have a colleague pull changes directly from you. Simply provide them with your public address, for example http://192.168.1.120/git/testproject.git, and they should now be able to clone your repo, add your remote, pull changes, etc.
If you want other people to be able to push to your repo you will have to explicitly allow this. In your testproject.git repo, set the http.receivepack value to true:
git config http.receivepack true