preface

In general, we configure a Git account on one computer, using the following command:

git config --global user.name "your name"
git config --global user.email "your email"
Copy the code

GitHub has been configured on my computer, now I need to configure the company’s GitLab account (or other types of Git account).

Configure multiple Git accounts

Clear the original global Settings

This step is not necessary. If you have not set the global username, email, and other information, do not clear the previous Settings

  • Unset global Settings
git config --global --unset user.name
git config --global --unset user.email
Copy the code

Generating an SSH Key

  • The SSH key of the Github account is generated
ssh-keygen -t rsa -C "[email protected]"
Copy the code
  • After the preceding command is executed, the following information is displayed
Enter file in which to save the key (/c/Users/admin/.ssh/id_rsa):
Copy the code
  • Change the ID_RSA file name here (note: do not overwrite the previous RSA key)
/c/Users/admin/.ssh/id_rsa_test
Copy the code
  • And then you just keep hitting enter

  • The SSH folder generates id_rsa_test and id_rsa_test.pub

  • Finally, paste the contents of id_rsa_test.pub into a specific location on the Github server

The preceding is only the SSH generation process of one account. The same goes for other accounts

Modify the config file (if not create one in the.ssh folder)

Git info for githunb Host test Git IdentityFile C:\ Users\ admin\.ssh\ id_rsa_test PreferredAuthentications publicKey # indicates that only the key is used, preventing the default PreferredAuthentications publickey Git info: The git info for company Host company Git IdentityFile C:\ Users\ admin\.ssh\ id_rsa_company # IdentitiesOnly yes PreferredAuthentications publickeyCopy the code

test

  • You can run SSH -t git@test to test whether the Github account is successful.

  • This completes the configuration

use

  • git clone
git clone git@test:worker/test.git
Copy the code
  • Run the config command to specify SSH keys for different Git accounts
Git config --global user.name "your name" git config --global user.email "your email" Git config --local user.name "your name" git config --local user.email "your email"Copy the code