Git multi-environment configuration

foreword

Recently, I just need to use different code hosting platforms. Originally, I pushed projects on GitHub, but now I need to push my own jobs on gitee, so I need to configure it here. Just record it, a blog about water~

Environmental preparation

In this case, I am still on the Windows platform. Of course, you are also on the Linux platform. Anyway, you are operating in the git environment, and it has nothing to do with your operating system. The same is true for Mac, but Mac should pay attention to its own version. Mac comes with one. After all, it is also Unix, which is the same family as Ubuntu and other Linux graphics distributions.
The cmd tool cmder for Windows is recommended here
insert image description here

clear the previous configuration

If you are a newly installed git skip, if not,
here is to clear your original configuration first

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

generate key

Git itself is also a small "Linux", and we are essentially similar to ssh to push files remotely.

Generate your secret key here, for example, I generate three here.
Here, first enter your git environment

insert image description here
Enter the following commands respectively to generate the secret key

ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "[email protected]"
ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitlab -C "[email protected]"
ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitee -C "[email protected]"

Then you will see these things in this directory
insert image description here

Configure Host

Now we have generated the secret keys of the three platforms (the whole process is actually very similar to the operation of ssh password-free login)

touch ~/.ssh/config    

Then we use vim to edit directly
insert image description here

Host github.com
        HostName github.com
        User git
        IdentityFile ~/.ssh/id_rsa.github

        Host git@gitlab.com
        HostName gitlab.com
        User git
        IdentityFile ~/.ssh/id_rsa.gitlab

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


This is clear at a glance, what does it mean? Actually, there is no need to write what Port 22 is, it is the default.
Later, if you have the hosting platform of your own company, it is the same configuration.

Add public key

I will demonstrate two platforms here, one is GitHub and the other is gitee,
first of all github

Github add

Found this in settings
insert image description here

insert image description here
insert image description here
At this time, go back to your git.
Since what you want to add is githu, you find this file
insert image description here
, copy the content inside,
insert image description here
and add it on the github page .
At this time, I added a
insert image description here

Gitee add

This is simpler
insert image description here
insert image description here

test

ssh -T git@github.com
ssh -T git@gitlab.com
ssh -T git@gitee.com

insert image description here

Then you can go to github gitee and happily pull the project

Guess you like

Origin blog.csdn.net/FUTEROX/article/details/123463712