I've been using Git more and more as my version control system, and I wanted to make some code available to the public. The easy option would be a hosted service like GitHub or repo.or.cz, but I'm vain enough to want to serve my code from barkingiguana.com. I don't need multiple committers, and I want to learn more about how Git works under the hood, so Gitosis would be overkill. It turns out that setting up your own public repository is pretty straightforward. Here's how I did it.
General setup
I already have Apache running (serving this blog, among other things), so I'll use that and serve code from repositories under http://barkingiguana.com/~craig/. The easiest way is to use mod_userdir. On Ubuntu, enabling it is trivial:
sudo a2enmod userdir
sudo /etc/init.d/apache2 restart
I want to keep my Git repositories under ~/code, which lets me selectively symlink in only the repositories I want to be public:
mkdir ~/code
My VM's SSH port is on a non-standard port, so I configured that in ~/.ssh/config on my local machine. I also took the opportunity to upload my SSH key.
Publishing a project
I have a project with some work already done locally that I'd like to share. First, create a bare repository on the public server:
# 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, on your local machine, add the public server as a remote:
# 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 up:
# On the local development machine
cd ~/sandbox/project_name
git push public master
The code is on the public server now, and you can push future changes with git push public master. But it still isn't web-accessible since it's not in ~/public_html. Fix that with a symlink:
ln -s ~/code/project_name.git ~/public_html/
Just like that, the repository is available for public use.
Did it work?
To verify everything is in order, try cloning the repository. Replace the URL 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