Working with Multiple Repositories on GitHub

- by

Apparently there’s been quite a buzz in the open source community lately about DVCSs in general and Git and Hg in particular. Up until pretty recently (sometime in the past week) I had totally missed the boat on this. However, I spent some time reading about them in a number of places, though apparently Dave Dribin’s writings are the only ones I bookmarked. None-the-less being a good the good little open source developer I pretend to be I thought I ought to at least tinker around with one of them and see what it was all about.

In mostly a snap decision I chose Git, though Linus’ highly entertaining tech talk may have influenced me. Either way, I already had a project I was working on, it isn’t exactly a compelling open source project but I didn’t have it under version control yet and it couldn’t hurt to get it somewhere. So having decided on Git I registered for a GitHub account and created a repository for it. The whole process was simple and easy, no problems there. Basically the premise behind GitHub is like a developer’s social network (well that and free Git repository hosting), you find a project you like and you follow (watch) it or you clone (fork) it. So then I saw John Resig’s tweet that his recently released Processing.js project was being hosted on GitHub and so I decided to fork it, look at the source and play around with it a bit.

The forking process was super easy, one click after being logged in and I had forked his project. No problems there but then I wanted to pull it down to my local machine or clone it so I had a working copy and here’s where I ran into problems. Executing git clone generated the following output.

Initialized empty Git repository in /Users/.../Projects/processing-js/.git/
ERROR: Permission to bryanjswift/processing-js denied to bryanjswift/bjs-wordpress.
fatal: The remote end hung up unexpectedly
fetch-pack from '' failed.

After a little research I figured out the problem was basically the wrong RSA key was being sent to GitHub and since GitHub uses the RSA key to identify you and determine if you have access to the repository or not my access was being rejected for one or the other of the repositories. Which repository depended on which RSA key was first on the list of the output from ssh-add -l

I could probably have written a pre-hook and post-hook for each of the git repositories I wanted to acess but given the nature of the man who wrote Git I knew there had to be a better solution. So I start digging around and I find a guide to multiple GitHub accounts. I realize this isn’t really the situation I’m in but it does indeed work. I set up an entry in my ~/.ssh/config for each of the two projects each looking something like

Host github-bjs-wordpress
User git
IdentityFile /Users/.../.ssh/bjs-wordpress_rsa

Happily this worked once I used the new Host entries as the ssh hosts; so became git@github-processing-js:bryanjswift/processing-js.git I could now access both my repositories. Hooray! Then I was poking around my account page on GitHub and found I can enter an RSA public key for my account and not just for each repository like I had already done. So I realize my mistake was entering myself as a collaborator on each repository and because I had done it that way I had to create multiple RSA keys for myself (GitHub makes each project collaborator on each project have a unique RSA key) which caused a mess.