create different ssh keys according the article Mac Set-Up Git
$ ssh-keygen -t rsa -C "[email protected]"
$ ssh-keygen -t rsa -C "[email protected]"
Please refer to github ssh issues for common problems.
For example, 2 keys were created at:
~/.ssh/id_rsa_user1
~/.ssh/id_rsa_user2
Before adding users, you can check existing keys:
$ ssh-add -l
or delete all cached keys:
$ ssh-add -D
Then, add these two keys as following:
$ ssh-add ~/.ssh/id_rsa_user1
$ ssh-add ~/.ssh/id_rsa_user2
Finally, you can check your saved keys:
$ ssh-add -l
$ cd ~/.ssh/
$ touch config
$ editor -a config # use your favorite editor - vim, nano etc...
Then add:
#user1 account
Host github.com-user1
HostName github.com
User [email protected]
IdentityFile ~/.ssh/id_rsa_user1
#user2 account
Host github.com-user2
HostName github.com
User [email protected]
IdentityFile ~/.ssh/id_rsa_user2
git clone [email protected]:user1/your_repo.git your_repo
cd your_repo and modify git config as needed, for example:
$ git config user.name "user2"
$ git config user.email "[email protected]"
editor .git/config
It should have this section:
[remote "origin"]
url = [email protected]:user2/your-repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
Make sure your url =
part has the exact same syntax, note the -user2
in [email protected]
.
or you can have global git config $ git config --global user.name "user2" $ git config --global user.email "[email protected]"
Like, share & profit!