Introduction
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 192.168.1.20 under git/agilesparkle, so my repository will be available at http://192.168.1.20/git/agilesparkle. 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-coreCreate directory for your git repository:
$ mkdir -p /var/www/git/agilesparkleCreate 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_fsConfigure Apache to serve git repository using dav:
$ vim /etc/apache2/conf.d/git.confCopy following inside the newly created file:
<Location /git/agilesparkle> DAV on AuthType Basic AuthName "Git" AuthUserFile /etc/apache2/passwd.git Require valid-user </Location>
Create new file with new user and his password:
$ htpasswd -c /etc/apache2/passwd.git myusernameRestart Apache server
$ service apache2 restartClient side
Clone the repository:
% git clone http://192.168.1.20/git/agilesparkle
Cloning into agilesparkle...
Username:
Password:
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 masterFor the following pushes you can simply use:
% git pushIf 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 ~/.netrcand add following:
machine 192.168.1.20 login myusername password mypassword