Skip to content

Instantly share code, notes, and snippets.

@hkasera
Last active September 29, 2018 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hkasera/bcdac17ff11d6442130a to your computer and use it in GitHub Desktop.
Save hkasera/bcdac17ff11d6442130a to your computer and use it in GitHub Desktop.
How to use multiple github accounts?

I have two accounts on github, one is personal account and other is office account. I typically face this problem to manage pushing to different repos using these different accounts.

I found a great way of doing it without any hassle.

Step 1 : Generate different ssh keys for both the accounts

Suppose my personal id is jane@gmail.com and office account is jane@doe.com

Follow the steps mentioned here to generate ssh keys : https://help.github.com/articles/generating-ssh-keys/

After creating ssh keys for both accounts I stored them in two different files,

The ssh key for jane@gmail.com is in ~/.ssh/personal_id_rsa and for jane@doe.com, the key is stored in ~/.ssh/office_id_rsa

Step 2 : Add these ssh keys in the ssh config file

Copy contents of this file to your ssh config.

The path of your ssh file will be ~/.ssh/config

Step 3 : Clone the repositories of both accounts

This is a crucial step. While cloning choose the ssh url, instead of https url. If the repo url is git@github.com:hkasera/binWatch.git, it should be cloned as per the path in ssh file. Since this is my personal account instead of using github.com I have to use github.com-hkasera

So to clone I execute this command : git clone git@github.com-hkasera:hkasera/binWatch.git

#Office Account
Host github.com-harshitakasera
HostName github.com
User git
IdentityFile ~/.ssh/office_id_rsa
IdentitiesOnly yes
#Personal Account
Host github.com-hkasera
HostName github.com
User git
IdentityFile ~/.ssh/personal_id_rsa
IdentitiesOnly yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment