Recently I got a problem when trying to manage between my personal GitHub account and my GitHub work account. I usually use ssh to clone the remote GitHub repository and when the first time I tried to clone the repository from my work account, it’s still tried to pull using my personal ssh key instead of my work ssh key, even I already set it up.
Here’s what I tried to do to fix it :
- Make sure I already set up my work ssh key
- Create entry in ssh config file, this will be used for managing different GitHub account , for example , I use this one :
Host github.com-personal
User personal-account
Hostname github.com
PreferredAuthentications publickey
IdentityFile /home/user/.ssh/id_rsaHost github.com-work
rsa_work
User work-account
Hostname github.com
PreferredAuthentications publickey
IdentityFile /home/user/.ssh/id_ - When cloning the GitHub repo , change the GitHub URL to the ssh config host, for example:
[email protected]:personal-account/personal-repo.git
- Configure the Git username and Email, for me I create a bash script to switch between my work account and personal account, since I using zsh, I create a simple bash script to export environment variable for bot account, and by default when I open my terminal it will configure to use my personal GitHub account