header image
Http Git Server
August 30th, 2011 under Linux, Programming. [ Comments: none ]

Eventually, I decided to give GIT a try. Therefore, I set up a GIT server on ganymede.ch. The server uses the handy git-http-backend

The git-http-backend is basically a cgi script that processes git requests. The set up is straight forward. First you have to make sure that apache can access and execute the git scripts. On Arch Linux this look like this:

1
2
3
4
<Directory "/usr/lib/git-core*">
    Order allow,deny
    Allow from all
</Directory>
<Directory "/usr/lib/git-core*">
    Order allow,deny
    Allow from all
</Directory>

To get the cgi script working I followed the manpage and added

1
2
3
4
SetEnv GIT_PROJECT_ROOT /srv/git
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER
ScriptAlias /git/ /usr/lib/git-core/git-http-backend/
SetEnv GIT_PROJECT_ROOT /srv/git
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER
ScriptAlias /git/ /usr/lib/git-core/git-http-backend/

Finally, we want some authentication and this can be done by

1
2
3
4
5
6
<Location /git/reposname>
        AuthType Basic
        AuthName "Private Git Access"
        Require group committers
        ...
</Location>
<Location /git/reposname>
        AuthType Basic
        AuthName "Private Git Access"
        Require group committers
        ...
</Location>

for read/write authentication or

1
2
3
4
5
6
7
<LocationMatch "^/git/reposname/git-receive-pack$">
      AuthType Digest
      AuthName "Git Repositories"
      AuthUserFile /srv/git/.git-auth-file
      AuthGroupFile /srv/git/.git-group-file
      Require group mygroup
</LocationMatch>
<LocationMatch "^/git/reposname/git-receive-pack$">
      AuthType Digest
      AuthName "Git Repositories"
      AuthUserFile /srv/git/.git-auth-file
      AuthGroupFile /srv/git/.git-group-file
      Require group mygroup
</LocationMatch>

I have an entry for each separate repository. This way I can have a fine grained access scheme by using different groups for different repositories.

NOTE: Unfortunately, I couldn’t figure out how to ScriptAlias / instead of /git to the CGI script. For more information see: stackoverflow

This gives a already a working GIT server. I installed also cgit to provide a webinterface.

What remains to be done is to create a repository. For this we execute git –bare init reposname. Make sure apache has all the necessary rights for this newly created repository.

That’s it!

Note: When you experience error messages during clone that mention something about update-server-info then you should execute git update-server-info in your repository and then enable the post-update hook containing exec git update-server-info (In my case this was the default in the post-update file). Btw: the hooks are located under hooks in the repository folder. Another issue is that right after git –bare init there is nothing in the repository. So, I had to do an explicit push the first time. This means I specified where I want to push (git push http://my_git_server/git/repos master).

On the client side it might be worth using

1
~/.netrc
~/.netrc
file with

1
2
3
    machine git_server.com
    login your_git_login
    password your_git_password
    machine git_server.com
    login your_git_login
    password your_git_password

This way you don’t have to pass the password everytime you push/pull to/from the GIT server.