Thursday, November 6, 2008

Pushing to multiple user accounts on GitHub

Here at Avvo, we've started to use GitHub for publishing some of our internal libraries that might be useful to the programming community. Although we have a company account, it's nice to have a personal account, too. Unfortunately, github doesn't allow multiple accounts to share the same SSH key. This makes sense, because all communication with github works using the same ssh user account. From my perspective, it can get kind of annoying. The key to being able to check code into multiple github accounts is setting up multiple ssh keys and using ssh aliases to use the correct key for the correct repo. First, I created a company-specific key:
justin-mac:~ jweiss$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/jweiss/.ssh/id_rsa): /Users/jweiss/.ssh/id_rsa.avvo
Enter passphrase (empty for no passphrase): 
Enter same passphrase again:
Then I set up an SSH alias in ~/.ssh/config:
host github-avvo
  User git
  IdentityFile ~/.ssh/id_rsa.avvo
Next, I copied the key into the avvo github acccount. Finally, when creating the clone of whichever repo I was using, I didn't use the clone path that github gave me, I translated it to use the alias I created. For example, a clone URL like
Now, when pushing to the central repository, it will pick up the id_rsa.avvo key that I tied to the avvo github account, and send the code to the right place.

No comments: