Mirroring a git repository

By Abhijit Menon-Sen <>

In a recent conversation on the Archiveopteryx mailing list, someone suggested that we move the code to Github because it feels very far away right now (hosted in a git repository on our own server). Some people agreed, and said that a project hosted on github (or SourceForge, or code.google.com) would get us more visibility, while others strongly preferred the status quo.

Although we decided against moving (and will instead focus on other ways to gain transparency and visibility as the project moves away from being company-driven), it was clear that having a mirror of our repository on Github (or elsewhere) couldn't hurt; and that's what this post is about.

The ten-second summary

The Archiveopteryx source code lives in a repository on git.aox.org, and the developers push commits to it. We set up github and gitorious as remote repositories on the server, and added a(nother) post-receive hook to push any new commits on to those two repositories. Voilà! Zero-effort mirrors of our code.

Gory details

On Github: I created an "aox" account, created an "aox" repository, and added arnt and myself (amenonsen, since both ams and abhijit were taken by people who aren't using their accounts) as collaborators.

On Gitorious: I created an account for myself (ams was free!), created a project named "aox", created a new "aox.git" repository, and added arnt and myself as collaborators on the project.

Then, in aox.git on git.aox.org, I did an initial push to both repository mirrors:

$ git remote add github git@github.com:aox/aox.git
$ git remote add gitorious git@gitorious.org:aox/aox.git
$ git push github
...
$ git push gitorious
...

To automatically push commits to both repositories in future, I created aox.git/hooks/post-receive with the following contents:

#!/bin/bash

nohup git push github &>/dev/null &
nohup git push gitorious &>/dev/null &

Update (2010-04-13): I put these two pushes into the background because I didn't want to wait for them to finish every time I pushed something to git.aox.org. But I was relying on ssh agent forwarding to authenticate with the remote servers, and that didn't work once my ssh client had disconnected. (I forgot to mention earlier that I have an entry in .ssh/config that sets ForwardAgent on for git.aox.org.)

So I switched back to blocking pushes, but that was so slow that Arnt and I decided to generate new keys to push to these repositories, and put them on git.aox.org rather than rely on agent forwarding. So the pushes run in the background again now, and it works fine.

Github and multiple accounts

The Github Terms Of Service say you shouldn't share accounts or create multiple accounts.

I found out about those restrictions not—I'm ashamed to admit—by reading the TOS but when I tried to add Arnt's SSH public key to the aox account so that he could push to it. It didn't work, because he'd added the same key to his own newly-created account. I was able to add my own key only because the amenonsen account I had created some time ago had an older ssh key on record.

I asked for advice, and was told that I could set up an aox account with no ssh keys, and just add anyone who was supposed to push to aox.git as a collaborator on the project. That sounded good, and seems to be common practice, but I didn't want to go against the spirit of the TOS. I found an old question on the Github support site where someone from Github says We try to discourage people from creating "project" accounts, but we won't stop you from making one.

That answer was dated December 2008, however, so I asked Scott Chacon of Github on IRC today if the practice was still discouraged. He said it was no problem, so I left our github mirror active.