Pushing to GitHub as two different users

So I recently decided to start using GitHub for both some personal and professional-related stuff. As these two areas can be very different, I decided that I wanted two separate GitHub accounts, but I wanted to be able to clone and push changes from either my work computer or my home computer (i.e. I might work on stuff either at work or at home, especially the professional-related items).

This can be done, but it took a bit of work. First, install and set-up Git on your machine. Test it, and make sure it works. Assuming this is the machine that you will be using two different accounts on, go back and generate a new set of ssh-keys, using the email address for your other GitHub account, and a different file name.

Probably try to give it some descriptive name so you know what it is

Now, in the ".ssh" directory, generate a file "config" if it doesnt exist, and set up a new host:

When you clone the repository you want to work on, use the ssh command like so:

cd into the directory, and also set your username and email address to correspond with that GitHub account for that local directory:

Now when you commit, the changes will be committed with the correct user, and more importantly when you "push" your changes back to GitHub, it will now use the alternative key that is set from the hosts file.

Based on information I found here: http://superuser.com/questions/232373/tell-git-which-private-key-to-use

Edit: GitHub assigns which user made which commit based on the user email address attached to the commit, so make sure you set the "user.email" correctly. If you are using GMail, you can add a "." anywhere in your email address and mail will still get to you, but GitHub (and Twitter, and others) will see it as a different address.

No comments:

Post a Comment