Follow below steps to add multiple accounts. More info at: https://gist.github.com/jexchan/2351996
goto .ssh folder and generate ssh keys for all your github accounts
$ cd ~/.ssh
$ ssh-keygen -t rsa -b 4096 -C "personal_email_id"
save as id_rsa_personal
$ ssh-keygen -t rsa -b 4096 -C "work_email_id"
save as id_rsa_work
Copy id_rsa_personal.pub and id_rsa_work.pub and add to respective github account.
Create config file in .ssh folder And add below configs
$ touch config
# Personal account - default config
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal
# Work account
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work
create .gitconfig for personal and work directory with respective config git host names
$ cd ~
$ nano ~/.gitconfig
[user]
name = personal_name
email = personal_email_id
[includeIf "gitdir:~/work/"]
path = ~/work/.gitconfig
$ nano ~/work/.gitconfig
[user]
name = work_name
email = work_email_id
Add new ssh keys
$ cd ~/.ssh
$ ssh-add id_rsa_personal`
$ ssh-add id_rsa_work
$ ssh-add -l
Check configuration is right by pinging to github with below commands
$ ssh -T github.com-personal
$ ssh -T github.com-work
Always clone repo by adding hostname in remote url e.g. [email protected] to [email protected]
git clone [email protected]:colormono/colormono.github.io.git
[email protected]:truenorth/multiple-git-accounts-demo.git