How to setup multiple git accounts for GitHub and Bitbucket

Issue #514

Generate SSH keys

1
2
3
4
5
6
7
8
9
ssh-keygen -t rsa -C "onmyway133@gmail.com" -f "id_rsa_github"
ssh-keygen -t rsa -C "onmyway133bitbucket@gmail.com" -f "id_rsa_bitbucket"

pbcopy < ~/.ssh/id_rsa_github.pub
pbcopy < ~/.ssh/id_rsa_bitbucket.pub

ssh-add -D
ssh-add id_rsa_github
ssh-add id_rsa_bitbucket
1
2
3
4
5
6
7
8
9
10
11
12
13
vim ~/.ssh/config

#Github (personal)
Host gh
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_github

#Bitbucket (work)
Host bb
HostName bitbucket.org
User git
IdentityFile ~/.ssh/id_rsa_bitbucket

Config

1
2
git config --global user.email "onmyway133@gmail.com"
git config --local user.email "onmyway133bitbucket@gmail.com"

Read more


Updated at 2020-10-04 06:52:07

Comments