So because it’s on a server there is no working directory required – as a result we do a bare initialise in the folder that we want the repo to be in:
1 |
git init --bare |
After that, to allow pushes to the server over http we need to run the following:
1 |
git config --file config http.receivepack true |
This will then work nicely with a virtual host in apache:
1 2 3 4 5 6 7 8 9 |
<VirtualHost *:80> ServerName git.server.com DocumentRoot /path/to/my/git/ SetEnv GIT_PROJECT_ROOT /path/to/my/git/ SetEnv GIT_HTTP_EXPORT_ALL ScriptAlias / /usr/libexec/git-core/git-http-backend/ </VirtualHost> |
Also, make sure the user running apache has write permissions to the git repository folders.
Authentication
To add some basic authentication I have used the following 2 techniques:
To make an entire repository private:
1 2 3 4 5 6 |
<Location "/private/"> AuthType Basic AuthName "Password Required" AuthUserFile /path/to/my/conf/passwd Require user username </Location> |
To make all repositories public for read and private for write:
1 2 3 4 5 6 7 8 |
<LocationMatch "^/.*/git-receive-pack$"> Options +ExecCGI AuthType Basic AuthName "Git Access" AuthName "Password Required" AuthUserFile /path/to/my/conf/passwd Require user username </LocationMatch> |
Web UI
Finally, I have used gitlist to provide a web ui to my repositories – to achieve this I used the standard approach documented here
My final config looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<VirtualHost *:80> <Location "/private/"> AuthType Basic AuthName "Password Required" AuthUserFile /path/to/my/conf/passwd Require user username </Location> <LocationMatch "^/.*/git-receive-pack$"> Options +ExecCGI AuthType Basic AuthName "Git Access" AuthName "Password Required" AuthUserFile /path/to/my/conf/passwd Require user username </LocationMatch> ServerName git.server.com DocumentRoot /path/to/my/www/gitlist/ SetEnv GIT_PROJECT_ROOT /path/to/my/git/ SetEnv GIT_HTTP_EXPORT_ALL ScriptAliasMatch \ "(?x)^/(.*/(HEAD | \ info/refs | \ objects/(info/[^/]+ | \ [0-9a-f]{2}/[0-9a-f]{38} | \ pack/pack-[0-9a-f]{40}\.(pack|idx)) | \ git-(upload|receive)-pack))$" \ /usr/libexec/git-core/git-http-backend/$1 </VirtualHost> |