This guide will describe how to serve git repository on HTTP port using Apache. This should work on any recent Ubuntu or Debian release, I’ve tested it on Ubuntu Server 11.10. I’m setting it up on my local server under git/agilesparkle, so my repository will be available at I want it to be password protected but with only single user with following credentials: myusername/mypassword.

Server side

I assume you have Apache installed already. Switch to root account so we won’t need to add sudo all the time and install git:

$ sudo su
$ apt-get install git-core

Create directory for your git repository:

$ mkdir -p /var/www/git/agilesparkle

Create bare git repository inside and set the rights so Apache has write access:

$ cd /var/www/git/agilesparkle
$ git --bare init
$ git update-server-info
$ chown -R www-data.www-data .

Enable dav_fs module. This will automatically enable dav module as well:

$ a2enmod dav_fs

Configure Apache to serve git repository using dav:

$ vim /etc/apache2/conf.d/git.conf

Copy following inside the newly created file:

<Location /git/agilesparkle>
	DAV on
	AuthType Basic
	AuthName "Git"
	AuthUserFile /etc/apache2/passwd.git
	Require valid-user

Create new file with new user and his password:

$ htpasswd -c /etc/apache2/passwd.git myusername

Restart Apache server

$ service apache2 restart

Client side

Clone the repository:

% git clone
Cloning into agilesparkle...
warning: You appear to have cloned an empty repository.

Create sample file and push it into empty repository:

% cd agilesparkle
% echo test file > readme.txt
% git add readme.txt
% git commit
% git push origin master

For the following pushes you can simply use:

% git push

If you don’t want to be prompted for the password each time and you don’t mind storing it in plain text, edit following file:

% vim ~/.netrc

and add following:

login myusername
password mypassword