I commit to Github for work and for personal use. For the last two months I have consistently had trouble each and every time I switch github contexts. Every night (and ev
The way you link a remote repo and different ssh keys in Git is through the remote url.
Change those urls like so:
cd /path/to/my/work/repo
git remote set-url origin workgh:myWorkLogin/myWorkrepo.git
cd /path/to/my/perso/repo
git remote set-url origin persgh:myPersoLogin/myPersorepo.git
See "How to work on personal GitHub repo from office computer whose SSH key is already added to a work related GitHub account?" as a full example.
Your ~/.ssh/config
will reference the right ssh key for each url:
# Personal GitHub
Host persgh
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_perso
# Work GitHub
Host workgh
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work
Don't use "github.com
" as a "Host": using an special name for the Host key is more explicit and indicates this is an ssh url you have to resolve through a ~/.ssh/config
file.