scene
On a computer, there are two repositories that belong to two different GitHub accounts.
step
Configure GitHub’s git account for repository
Use the terminal to enter the repository a directory and configure the GIT account
$ git config user.name "user_a"
$ git config user.email "[email protected]"
Use the terminal to enter the repository B directory and configure the GIT account
$ git config user.name "user_b"
$ git config user.email "[email protected]"
Generating SSH keys for different GitHub users
For user_ A generates an SSH key named user_ A_ Id_ RSA
$ ssh-keygen -t rsa -C "[email protected]"
The same operation, for user_ B generates an SSH key named user_ B_ Id_ RSA
$ ssh-keygen -t rsa -C "[email protected]"
Configure SSH matching of multiple accounts
In the. SSH directory, create a new config file and configure the key of multi-user
host user_a_github.com
Hostname github.com
User git
IdentityFile ~/.ssh/user_a_id_rsa
host user_b_github.com
Hostname github.com
User git
IdentityFile ~/.ssh/user_b_id_rsa
Add a new private key to the SSH agent cache
$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/user_a_id_rsa
$ ssh-add ~/.ssh/user_b_id_rsa
Modify the push address of the repository
For the URL field value of. Git / config in the repository[email protected]Modification.
Modify the push address of repository a:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = [email protected]_a_github.com:*********/***********.git
fetch = +refs/heads/*:refs/remotes/origin/*
[user]
name = user_a
email = [email protected]
Modify the push address of repository a:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = [email protected]_b_github.com.com:******/******.git
fetch = +refs/heads/*:refs/remotes/origin/*
[user]
name = user_b
email = [email protected]
That’s it.
Some orders
#Check current user
ssh -vT [email protected]
#Check the original key
ssh-add -l
#Add key
#Delete key
ssh-add -d /Users/****/.ssh/id_rsa
#View git config configuration
git config --list
This work adoptsCC agreementThe author and the link to this article must be indicated in the reprint