Background requirements:
During the process of work and learning, we often encounter multiple Gits on a computer, such as Gitee, Github, WeChat Git, etc.
For example, there are local projects A, project B, and project C on the same computer. Project A is hosted in Gitee, Project B is hosted in Git, and Project C is hosted in Github.
Background knowledge:
First of all, we know that when pulling code, there are 2 commonly used methods. The different hosting platforms, in fact, support for these two methods is different from the
HTTPs method and the ssh method
.
Solution:
Operation method 1-HTTPS method
Win uses an account password to configure windows credentials (cannot support github, not applicable to Mac, Linux):
Step 1: Search to find win credential manager
Step 2: Configuration credentials
Current user name configures email, password configures the platform's password, and pulls and pushes can be achieved.
Step 3: pull, push
Operation method 2-SSH method, configure SSH
Step 1: Open git bash there, and switch to the ssh directory
cd ~/.ssh/
Step 2: Generate the required key pair
# Prepare to github's
$ ssh-keygen -t rsa -C "[email protected]" -f github_rsa
# Prepare to gitee's
$ ssh-keygen -t rsa -C "[email protected]" -f gitee_rsa
file generated as shown in the following figure
command each time, generate two files, one public key and one private key.
The pub suffix is the public key. It should be placed on the corresponding cloud platform.
Step 3: Put the public key to the corresponding cloud platform. Take github as an example
First in githml4 bash, use the cat command to get the public key information
and then copy the content, open the personal setting of github, add ssh key
Step 4: Configure config to let the computer know which cloud platform should use which key.
in the .ssh directory, create a new config file (note that the full name is config without a suffix)
fills in the configuration information in it and tells the computer how to make choices.
If there are more sites, just add it later.
Step 5: Test connection
ssh -T [email protected]
Step 6: Project test
For github, the first push requires two verifications. The first time I entered github's login username and password
The second time I entered is token
generated on github, be sure to copy and save it. After exiting the page, you can't see it and can only be regenerated.
Step 7: The job is done! ! ! ! ! ! !
push operation is successful.
also has the same operation for gitee. First ssh -t test the connection, then git pull and git push (Gitee does not need to set up a token at the moment, the first push will be relatively simple)
Reference article:
https://blog.csdn.net/felicity294250051/article/details/53606158
https://blog.csdn.net/pinnuli/article/details/81293071
https://blog.csdn.net/weixin_46622106/article/details/111914231