Installing a Git Server using Apache (WebDAV) on Ubuntu Server 12.04

This tutorial is mainly for Ubuntu Server 12.04, meaning I’ve implemented and tested it fully on a Ubuntu 12.04 server this will more than likely work on other versions of Ubuntu/Debian based distro’s too though!

So, whats this tutorial all about then… well this allows you to run your own (private) Git Server using WebDAV (Apache2) to enable a simple way to host a Git Server, sure you can use GitHub for public hosting but if you have some ‘private’ stuff that you want to keep control of and don’t really want to spend the monthly fee for a GitHub private repo you can implement a private git repo server yourself and very easily – Although this tutoial is mean’t as just the basics, I’d personally recommend that you configure SSL (HTTPS) if you intend to use this in a production environment/communication over the internet.

On the Server

1) Install Ubuntu Server, this is the base of our git server obviously

2) Now we need to install a couple of packages, these being ‘git-core’ and ‘apache2′, we do this like so:-

apt-get update
apt-get install apache2 git-core

3) Now we need to create a new folder for your new repository and set some inital permissons, we do this like so:-

6) Next we need to create a user account of which you will need to use to browse of commit to the repository..

htpasswd -c /etc/apache2/passwd.git <user>

You could then be prompted to enter the password for the user too and confirm it!

7) Ok that’s it for the server side configuration… we just need to restart Apache2 like so and then we should be ready to move on to the client side stuff!

/etc/init.d/apache2 restart

…you can now move on to the client side stuff!

On the client side

Ok so now we need to create a local (on your desktop machine) repository and then we’ll initiate the new remote repository… So, if your using Linux/MacOSX bring up the terminal and type the following commands:-

Done! – Your intiial file named ‘README’ which currently is just blank has now been committed and you’ve pushed your code to your new git server which has now completed the Git reposity creation process, now in future you can ‘clone’ your resposity like so:-

git clone <user>@<server name or IP address>/test-project.git

Easy huh? – Whats really good it that by using HTTP you can get around corporate firewalls too, no need to have outbound SSH ports open of which most corporate companies block anyway!

Like I say, you may however want to look into configuring Apache to use an SSL certificate, I personally don’t need this as I just installed on my new home server which I do not need HTTPS so I haven’t bothered, I also guessed that by keeping this post simple you’d get the bigger picture anyway