Several problems and solutions of GIT are summarized

Time:2021-7-27

preface

Originally, when I learned git, I only knew a few basic usages. When I encountered problems, I got confused. This time, I summarize several problems encountered in history and countermeasures.

Clone error

Several problems and solutions of GIT are summarized
The first is a project that downloaded GitHub this week. The package error is shown in the figure above. The general meaning of the error is that the data to be read has not been completed, but the connection to transmit the data has been closed. I have tried countless methods on the Internet.
Cause 1: buffer overflow
Solution: command line input

git config http.postBuffer 524288000

Set the cache to 500m,
Reason 2: slow network download speed
Solution: command line input

git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 999999

Configure the lowest speed and time of GIT. If the clone still fails, first shallow clone, and then update the remote library locally

git clone --depth=1 http://gitlab.xxx.cn/yyy/zzz.git
git fetch --unshallow

Finally, I successfully solved it through these two commands.

Pull branch from remote git warehouse

After successfully cloning the project, the teacher asked me to switch to branch 102, but I don’t have branch 102 locally. What should I do. After another online method test, it was solved smoothly.
1.

git branch -a

Look at the local branch. Of course, there are no 102 branches in the branch we just pulled down from the remote git warehouse.
2.

git fetch origin 102

Pull 102 branches from remote git warehouse to local warehouse
3.

git checkout -b 102

Create a new 102 branch locally
4.

git pull origin 102

Pull 102 branch to local.
Or if you haven’t cloned the remote warehouse code, you can directly clone a branch of the remote warehouse to the local

git clone -b 102 https://xxx.git

Local and remote codes do not match

git push origin XXXIt’s a mistake

error: failed to push some refs to 'https://git.XXX.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

This is because for the first timegit push origin XXXWhen the remote warehouse has made other changes, you click synchronize the latest changes, and then think about itgit push origin XXXWhen the code of the branch is inconsistent with that of the remote warehouse.
You need

git pull origin XXX

Merge remote branch code to local branch. Then submit.
Or when someone else submits the code, you can update your code to be consistent with the remote warehouse code.

git fetch 
git merge origin/master

summary

I saw a picture on the Internet, which can help understand the GIT command. I’ll share it with you here
Several problems and solutions of GIT are summarized

Copyright notice

Author: Zhao Kaiqiang, mengyunzhi development team of Hebei University of Technology