Git connect to remote warehouse

Article reprinted from:  

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 ( 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( 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( 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 "yourname"

git config --global ""

2. Generate key (SSH key)

ssh-keygen -t rsa -C ""

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 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

b.  ssh -T

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 remote add origin

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 configure config file stay./ssh If not in the directory config Files are created # Configure github
HostName IdentityFile C:\\Users\\zzw\\.ssh\\id_rsa_github
PreferredAuthentications publickey
User ZeroBound

# Configure gitee
Host HostName
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
  2.ssh -T   d.Enter the warehouse directory to configure the user name and mailbox   git config "yourname"   git config ""



8, Related issues

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

git pull origin master
fatal: unable to access '': 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

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