When you are working in separate accounts, 1 for work-related and 1 for personal, you might encounter permission denied error, for example, saying that your work account is not allowed to push commit to your personal repo. On this config, I am using default github.com for work and then github.com-personal for personal account.
$ cd ~/.ssh
$ ssh-keygen -t rsa -b 4096 -C "your_personal_email@domain.com"
# save as id_rsa_personal
$ ssh-keygen -t rsa -b 4096 -C "your_work_email@domain.com"
# save as id_rsa_work
Listing .ssh folder will give you 4 files
id_rsa_personal
id_rsa_personal.pub
id_rsa_work
id_rsa_work.pub
pbcopy < ~/.ssh/id_rsa_personal.pub
If pbcopy is not installed, you can use cat ~/.ssh/id_rsa_personal.pub
then copy contents.
Go to github.com and click on your profile picture. then:
Settings > SSH and GPG keys > New SSH key > Paste key > Add SSH key
Paste the following:
# Personal account - default config
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal
# Work account
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work
I use vim to edit in CLI, if vim is not installed, you can use nano
vim ~/.gitconfig
Content:
[user]
name = Gerlie Reyes
email = gerlie.reyes@work.com
[includeIf "gitdir:~/personal/"]
path = ~/personal/.gitconfig
vim ~/personal/.gitconfig
Content:
[user]
email = mendozagerlie@gmail.com
cd ~
ssh-add -D
On Windows cmder, you might encounter error: 'eval' command is not recognized. Make sure to select bash command in cmder + button.
ssh-add id_rsa_personal
ssh-add id_rsa_work
git remote add origin git@github.com-personal:gerlie-reyes/learn-react.git