Git connect to remote warehouse

Article reprinted from: https://www.cnblogs.com/zeo-to-one/p/8367801.html  

How do I use Git to connect to a remote warehouse? Remote warehouse - > generally refers to the code hosting platform. Let's take a look at three familiar Version (code) hosting service platforms.

 

Version (code) managed service platform:

Code cloud (gitee.com): it is a Git based fast, free and stable online code hosting platform launched by the open source Chinese community team, without limiting the number of private and public libraries

Coding(coding.net): it is a one-stop development platform under CODING. It provides git/svn code hosting and supports private (limited) and public libraries for free

github(github.com): it is the world's largest open source community and a version hosting platform based on git. Private libraries need to be paid, and the access speed is slow.

 

Prerequisite preparation:

1. Download and install git tools (just next). download   >>> 

2. Register on GitHub / code cloud / Coding.   Code cloud >>> coding>>>   github>>>

When the premise is ready, you can start the connection between Git and the remote warehouse. Here, take github as an example.

 

1, Git configuration

1. Set the user name and mailbox (- - Global as the global parameter, indicating that all local Git warehouses will use this configuration)

git config --global user.name "yourname"

git config --global user.email "your_email@youremail.com"

2. Generate key (SSH key)

ssh-keygen -t rsa -C "your_email@youremail.com"

3. Add a key (SSH key) and verify whether it is successful

Add key: the key generated in the previous step, namely. SSH / ID_ Copy all contents in rsa.pub. Paste the copied content (Title custom) in settings -- > SSH and GPG keys -- > New SSH key in github.

Verification: github enters the first command, and the code cloud enters the second command

a.  ssh -T git@github.com

b.  ssh -T git@gitee.com

2, Create project project

1. Remote warehouse: enter Repository name in github New repository. [example: TestDemo]

2. Project project: create a new folder with the same name as the github project on your local computer. [example: TestDemo]

3, Create version Library

  Enter the folder in step 2 and enter the following command to initialize the warehouse. If it appears: Initialized empty Git repository in   E:/** /**/.git / indicates successful creation [Note: a. Git directory (hidden directory) will be generated at this time]

git init

4, Connect to the remote warehouse (both of the following methods can be used)

git remote add origin git@github.com:yourName/repositoryname.git
git remote add origin https://github.com/yourName/repositoryname.git

5, pull the file from the remote warehouse (if there is no file in the remote warehouse, directly execute step 6)

git pull origin master

6, push the local file to the remote warehouse (create it manually if there is no file)

git status          View the status of the working directory

git add <file>        Add files to staging area

git commit -m "commnet"   Submit changes,Add notes(The information of the staging area is submitted to the local warehouse)

git push origin master    File from local warehouse push To remote warehouse(if push Unsuccessful, can be added -f Perform push operation)

  Note: so far, the configuration of remote and local warehouses has been completed. If separate configuration is required, see the following operations

7, Generate multiple keys (multiple accounts) and configure different remote warehouses [account number configured as local variable]

a.Add new ssh-key If an error is reported: Could not open a connection to your authentication agent.Unable to connect to ssh agent;Executable ssh-agent bash Execute after command ssh-add command   ssh-add ./id_rsa_github   ssh-add ./id_rsa_gitee   b.to configure config file stay./ssh If not in the directory config Files are created # Configure github
Host github.com
HostName github.com IdentityFile C:\\Users\\zzw\\.ssh\\id_rsa_github
PreferredAuthentications publickey
User ZeroBound

# Configure gitee
Host gitee.com HostName gitee.com
IdentityFile C:\\Users\\zzw\\.ssh\\id_rsa_gitee
PreferredAuthentications publickey
User zhzw   c.reach github Or add a key to the code cloud, and then verify whether it is successful   1.ssh -T git@github.com
  2.ssh -T git@gitee.com   d.Enter the warehouse directory to configure the user name and mailbox   git config user.name "yourname"   git config user.email "your_email@youremail.com"

 

 

8, Related issues

Q1.   git pull origin master cannot pull, and the following prompt appears:

git pull origin master
fatal: unable to access 'https://github.com/yourName/Demo.git': error setting certificate verify locations:
  CAfile: G:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
  CApath: none

Analysis: the ca-bundle.crt file is a certificate file. According to the prompt, caspath: none does not have the file, so the remote warehouse cannot be accessed

Solution: modify to the correct path or set the certificate verification to false

git config --system http.sslcainfo E:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
git config --system http.sslverify false

  The following prompt appears in Q2.git pull origin master:

fatal: refusing to merge unrelated histories

Solution: it can be solved by the following operations

git pull origin master --allow-unrelated-histories

Q3. You need to enter the user name and password every time you git push origin master:

Because the https protocol is used during configuration, you need to enter it every time

git remote -v  View remote connections

git remote rm origin  Delete remote connection

git remote add origin git@github.com:yourName/repositoryname.git

Posted on Mon, 08 Nov 2021 00:47:53 -0500 by big_c147