Gist

Multiple Git Accounts on single machine

How to use multiple GitHub accounts on one machine: configure separate SSH keys and ~/.ssh/config hosts, clone with custom hostnames, and set per-repo git http://user.name and http://user.email safely.

Head back over to the SSH config file at ~/.ssh and amend accordingly to:

#user1 account
Host github.com-user1
   HostName github.com
   User git
   IdentityFile ~/.ssh/github-user1
   IdentitiesOnly yes

#user2 account
Host github.com-user2
   HostName github.com
   User git
   IdentityFile ~/.ssh/github-user2
   IdentitiesOnly yes

Replace user1 or user2 with your GitHub usernames/identification-handlers

Go ahead to git clone your respective repository

git clone [email protected]:user1/your-repo-name.git your-repo-name_user1

Configure your git identity:

  • Open up local git config using git config --local -e and add:
[user]
    name = user1
    email = [email protected]

More detailed reference

https://gist.github.com/Jonalogy/54091c98946cfe4f8cdab2bea79430f9