More and more these days I'm using Git as my version control system. I want to make code available to the general public. The easy choice would be to use a service like GitHub or repo.or.cz but I'm vain and want to serve my code from barkingiguana.com. I don't need to support multiple committers and I'd like to learn more about how Git works so I don't want to use Gitosis. It turns out that it's pretty easy to setup your own public repository. Here's how I did it if you'd like to try the same.

General Setup

I've already got Apache setup (serving my blog among other things) so I'll use that and serve code from repositories under http://barkingiguana.com/~craig/. The easiest way to do this is to use mod_userdir. Since I'm using Ubuntu it's really easy to enable this module.

sudo a2enmod userdir
sudo /etc/init.d/apache2 restart

I'd like to keep my Git repositories under ~/code since this will let me selectively link in this repositories that I'd like to be public.

mkdir ~/code

The SSH port for my VM is on a non-standard port so I needed to put that into ~/.ssh/config on my local development machine. I also took the opportunity here to upload my SSH key to the VM.

Publishing a project

I've got a project that I'd like to publish. It's got a bit of work already done locally and I'd like to share that with the public. First I need to create a bare repository on the public machine.

# On the public server
mkdir -p ~/code/project_name.git
cd ~/code/project_name.git
git --bare init
chmod +x hooks/post-update

Success looks like this:

Initialized empty Git repository in /home/user_name/code/ project_name /

Next I setup my local development repository with an alias for the public repository because I'm going to push to this fairly regularly.

# On the local development machine
cd ~/sandbox/project_name
git remote add public ssh://barkingiguana.com/~/code/project_name.git

Now push the local master branch to the public repository.

# On the local development machine
cd ~/sandbox/project_name
git push public master

Ace, the code is on the public server and I can easily push changes that I've merged back into the local master branch to the remote repository by running git push public master. The code still isn't available to the public though since it's not in my ~/public_html. Link it in now.

ln -s ~/code/project_name.git ~/public_html/

Bam, just like that the repository is available for public use.

Did it work?

To make sure everything went okay, try cloning the repository. If you're following along at home remember to replace http://barkingiguana.com/~craig/addressbook.git with wherever your repository lives.

# On the local development machine
mkdir ~/tmp/
cd ~/tmp/
git clone http://barkingiguana.com/~craig/addressbook.git

Success should look something like this:

Initialized empty Git repository in /Users/craig/tmp/addressbook/.git/
got d0cc5f06e1d164ea6ada301dbd2e7c946d1ae532
walk d0cc5f06e1d164ea6ada301dbd2e7c946d1ae532
got b68d1319a780a776afdb60e3bba2985793a11f3e
got 2baa33597deecfc3eb558c59bc69745e153f9b82
got da7110115566b026c7316bd1be4cbf3d76c0f656

Found this article useful?

If you enjoyed this article I'd appreciate recommendations at Working with Rails.

written by
Craig
published
2008-11-15
Disagree? Found a typo? Got a question?
If you'd like to have a conversation about this post, email craig@barkingiguana.com. I don't bite.
You can verify that I've written this post by following the verification instructions:
curl -LO http://barkingiguana.com/2008/11/15/setting-up-a-public-git-repository.html.orig
curl -LO http://barkingiguana.com/2008/11/15/setting-up-a-public-git-repository.html.orig.asc
gpg --verify setting-up-a-public-git-repository.html.orig{.asc,}