Recently, I ran into a situation where I needed to manage multiple Github accounts from a single computer. I have two github account, one related to work and the other for my personal repositories.
It is a very simple combination of ssh and git config. Before I start explaining the steps for the same, let me clarify that the following steps are meant for LINUX/UNIX users.
1. Set up SSH keys
You will need to set up two different ssh keys for the two accounts.
Make sure that when prompted for the filename when generating the ssh keys for the second account, you give the appropriate filename.
2. Add the ssh key to your github account
> On your github account, Go to your Account Settings
> Click “SSH Keys” then “Add SSH key”
> Paste your key into the “Key” field and add a relevant title
> Click “Add key” then enter your Github password to confirm
> Repeat this step for your other account with the appropriate keys.
3. Create a ssh configuration file to manage the two separate keys
$ touch ~/.ssh/config
Add the following in your ~/.ssh/config file.
Once you save this file, you need to configure your git repos on local accordingly.
4. Setup your repo
Replace “email@example.com” part in the remote origin of all your personal repositories to “firstname.lastname@example.org”
And that’s it. From now on, the appropriate user account will be used for pushing to these repositories.