www.thorko.de Thorsten Kohlhepp - Systems administrator | Git over HTTP

 

Git over HTTP

Prerequisite

Apache with mod_dav enabled
and git

To enable mod_dav on apache:
on debian
a2enmod dav dav_fs

To enable DAV manually create a dav.conf file and include it in your main apache configuration file

LoadModule dav_fs_module /usr/lib/apache2/modules/mod_dav_fs.so
LoadModule dav_module /usr/lib/apache2/modules/mod_dav.so
DAVLockDB /var/lock/apache2/DAVLock

make sure the lock file is writeable by the apache user

create a virtual host in your apache configuration

<VirtualHost *:80>
    ServerName git.localhost
    DocumentRoot /var/www/git
    <Directory /var/www/git>
        Dav on
        AuthType Basic
        AuthName "Git"
        AuthUserFile /etc/apache2/passwords/git
        <LimitExcept GET HEAD OPTIONS>
            Require valid-user
        </LimitExcept>
    </Directory>
</VirtualHost>

create the password file

htpasswd -c /etc/apache2/passwords/git <username>

create the git repository on the webserver

mkdir /var/www/git
cd /var/www/git
git --bare init
chown -R <apache user>: /var/www/git

move the post-update script and make it executable

mv /var/www/git/hooks/post-update.sample /var/www/git/hooks/post-update
chmod a+x /var/www/git/hooks/post-update

on the client do a clone

git clone http://git.localhost/git

you will get an empty repository. Now add some files to it.

touch README INSTALL; git add README INSTALL; git commit

Once you have done this push it to the server

git push origin master

If you get an error like this "Unable to lock remote branch refs/heads/master" check that you don't have a .htaccess file lying around which overwrites some settings.