Let's talk about the problem of git multiple accounts.
Background
When using git, we all face the problem of multiple accounts. The most common problem is the company's internal gitlab and the open source platform github. We all need to use it on the same computer at the same time, which needs to solve two problems.
Git multi-account configuration
Git config-global user.name sets the global user name
Git config-global user.email Design Global Mailbox
The git config-global setting works on all git repository by default. When we git clone the repository of gitlab and github respectively, we need to set the user.name and user.email of the current warehouse for the repository under each git clone.
For this question, please refer to my git series-> talk about the precautions before using git.
Ssh multi-key pair configuration
We all know that git is based on the ssh protocol, and git establishes remote links and authentication through ssh agent.
Ssh is encrypted and transmitted to git server through the rsa private key, and git server decrypts it by finding the corresponding rsa pub key to verify whether the legal information is currently submitted.
We create different rsa key pairs through ssh-keygen. If you have not specially handled the private key pairs within the company, the default names are id_rsa and id_rsa.pub.
If this is the first time we have created a git account, we can simply default the creation process for the first time
Ssh-keygen-t rsa
Enter enter all the way, then configure the gitlab within the company, and submit normally.
Then create it with another name through ssh-keygen, such as github and github.pub, which is no different from creating the default id and id.pub.
Then add the newly created github private key to the ssh-agent cache through ssh-add.
Ssh-add / .ssh/github
Then look at the list of ssh agent keys cache.
Ssh-add-l
Then configure the github.pub public key to our github account.
Then you can use gitlab and github normally. If you are worried about the confusion of the two key, you can remove one of the key from the ssh agent.
Ssh-add-d ~ / .ssh/github
Then try the git push code, and if it's good, it's right.
Thank you