This guide lists all the step you need to take to install a git server which is accessible via http. If you have no need for https you can skip this part in the tutorial. After following all the steps it did not work immediately, I did have to tweak the apache configuration a little and install additional packages, the end result can be found below.
The git-core package was also installed using apt-get install git-core.
This VirtualHost configuration also limits access to only IP addresses in the subnet 192.168.*.* and requires a password, stored in the htpasswd file located at /var/www/git.example.com/git.passwd
Pay special attention to this line: ScriptAlias /git/ /usr/lib/git-core/git-http-backend/ and verify that the location of the git-core directory is correct. On some installations the path might be /usr/libexec/git-core/git-http-backend or something similar.
<VirtualHost>
ServerAdmin webmaster@localhost
ServerName git.example.com
DocumentRoot /var/www/git.example.com/htdocs
<Directory>
Options FollowSymLinks
AllowOverride None
</Directory>
SetEnv GIT\_PROJECT\_ROOT /var/git/repository
SetEnv GIT\_HTTP\_EXPORT\_ALL
SetEnv REMOTE\_USER=$REDIRECT\_REMOTE\_USER
ScriptAlias /git/ /usr/lib/git-core/git-http-backend/
<Location>
Deny from all
Allow from 127.0.0.1
Allow from 192.168
</Location>
<Location /git>
AuthType Basic
AuthName "Git Repository"
AuthUserFile /var/www/git.example.com/git.passwd
Require valid-user
</Location>
ErrorLog ${APACHE\_LOG\_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
LogLevel warn
CustomLog ${APACHE\_LOG\_DIR}/access.log combined
</VirtualHost>
Read the next git blog post to learn how to also browse the git repositories using your webbrowser.
Create new git repository
To create a new git repository execute:
git init <span class="hljs-comment">--bare name_of_project.git</span>
On a remote machine you can checkout this project by executing:
git <span class="hljs-keyword">clone</span> <span class="hljs-title">http</span>://git.example.com/git/name_of_project.git
On the first push command to send the changes to the server, you need to specify that you were working on the master. The original repository was bare, so git does not know that yet. The command below takes care of that:
git <span class="hljs-built_in">push</span> <span class="hljs-built_in">origin</span> master