Technology Sharing

Git configures Gitee and GitHub at the same time

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

1. Clear old users

If you have previously setTortoiseGitCheck it in the software, as shown in the figure:
insert image description here
You can use the following command to clear the global settings [recommended]:

git config --global --unset user.name "你的名字"
 git config --global --unset user.email "你的邮箱"
  • 1
  • 2

For example:

git config --global --unset user.name "qiandu"
git config --global --unset user.email "[email protected]"
  • 1
  • 2

Or with the help ofTortoiseGit

insert image description here

Check whether the clearing is successful

git config --global --list
  • 1

If user and email do not appear, it means the global settings have been cleared successfully!

2. Set up users

git config --global user.name   "你的名字"
git config --global user.email  "你的邮箱"
  • 1
  • 2

For example:

git config --global user.name   "qiandu"
git config --global user.email  "[email protected]"
  • 1
  • 2

or

insert image description here

3. Generate SSH public and private keys

Please change the email address to your own!

ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/gitee_id_rsa
  • 1
ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/github_id_rsa
  • 1

Note that after entering the command to generate the SSH-key, you need to press Enter three times, which means empty, that is, "empty" means there is no password.
insert image description here

4. Create a new configuration file

Create a new config file in the ~/.ssh directory [C:UsersUsername.ssh] and add the following content (Host and HostName are filled with the domain name of the git server, and IdentityFile specifies the path of the private key)

# github
Host github.com
    HostName github.com
    User git
    Port 443
    IdentityFile ~/.ssh/github_id_rsa

# gitee
Host gitee.com
    HostName gitee.com
    User git
    Port 22
    IdentityFile ~/.ssh/gitee_id_rsa

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
ssh-add ~/.ssh/gitee_id_rsa
ssh-add ~/.ssh/github_id_rsa
  • 1
  • 2

Confirm that the ssh-agent process is running: Run eval $(ssh-agent) to start or restart the authentication agent.

 eval $(ssh-agent)
  • 1

After adding, you can verify it by executing the following code.

ssh-add -l
  • 1

5. Add the corresponding public key to Gitee and GitHub

Gitee public key:gitee_id_rsa.pub
GitHub public key:github_id_rsa.pub
insert image description here
insert image description here

6. Testing

ssh -T [email protected]
ssh -T [email protected]
  • 1
  • 2

insert image description here