Using multiple git profiles on the same machine
When using public key authentication to clone and use a git repository, one might want to use a different identity for certain repos, while leaving the default identity alone. One way to get around this on a Mac, which has worked quite well for me is to use the .ssh/config file to create individual profiles, and then to clone the repos using the appropriate configuration for each repo.
Update email id and possibly name for repo
ssh-keygen -t rsa -C "<email>" -f '$HOME/.ssh/id_rsa_personal'The default identity was already stored under id_rsa.
Now edit ~/.ssh/config
Contents of .ssh/config
# Default account
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
# Personal account
Host github_personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personalNow when cloning your repo, use:
Modify githubuser and githubrepo for your use case
git clone git@github_personal:<githubuser>/<githubrepo>.gitThis should clone the new repo. All subsequent git commands in this repo would point to your other identity (in my case my personal github identity).