Git命令报错合集

2023-11-26  本文已影响0人  骑着蜗牛去攻城

1.git pull报错:

There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

原因:本地仓库和远程仓库的分支没有做关联。

解决:运行git branch --set-upstream-to=origin/<branch> master,给本地master分支设置一个上游分支或者说是跟踪分支。

2.git pull报错:

fatal: refusing to merge unrelated histories

原因:本地仓库和远程仓库存在不同的提交记录。

解决:运行git pull origin master --allow-unrelated-histories,后面加上--allow-unrelated-histories,把两个不相干的分支进行强行合并

3.git pull报错:

fatal: unable to access 'https://github.com/xxxx/xxxx.git/': SSL certificate problem: unable to get local issuer certificate

原因:一般是连接github的时候会报的错,一般是这是因为服务器的SSL证书没有经过第三方机构的签署,所以才报错。

解决:参考网上解决办法,输入下面代码,解除ssl验证后,再次git即可。

git config --global http.sslVerify false

4.git push报错:

fatal: The current branch wangxiao has no upstream branch.
To push the current branch and set the remote as upstream

原因:这是因为本地的分支没有和远程分支建立联系

解决:执行 git push --set-upstream origin master,或者在pull的时候就执行git branch --set-upstream-to=origin/<branch> master建立上游分支。

5.git push报错:

fatal: The upstream branch of your current branch does not match
the name of your current branch.  To push to the upstream branch
on the remote, use

    git push origin HEAD:main

To push to the branch of the same name on the remote, use

    git push origin HEAD

To choose either option permanently, see push.default in 'git help config'.

原因:本地仓库和远程仓库的分支名不同,不知道要push那个本地分支到远程分支。我这边github新仓库的默认分支是main,本地仓库分支是master。

解决:共3中方法:

1.更改远程仓库分支名,把远程分支改成master。

2.①更改本地仓库分支名为main:

git branch -m main

②然后执行下面代码,忽略本地和远程仓库不同的提交记录,强行合并。

git pull origin main --allow-unrelated-histories

③执行下面代码,把本地分支和远程分支关联。

git branch --set-upstream-to=origin/main main

注意:如果先进行步骤③,再进行步骤②的话,在执行步骤③的时候就会报错:

error: the requested upstream branch 'origin/main' does not exist
hint: 
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint: 
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.

3.采用git的push默认配置push.default中的upstream选项,从哪pull的就push到哪。

git config push.default upstream

6.git branch --set-upstream-to=origin/master master报错:

error: the requested upstream branch 'origin/master' does not exist
hint: 
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint: 
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.

原因:我这边报错的原因是因为远程仓库是github,现在的github把默认分支改成了main,而本地git的默认分支是master。

解决:把origin/master改成origin/main就行了:

git branch --set-upstream-to=origin/main master

7.git pull origin master --allow-unrelated-histories报错:

fatal: couldn't find remote ref master

原因:还是因为现在的github建立的仓库默认分支是main,没有和本地仓库关联。

解决:运行下面代码:

git pull origin main --allow-unrelated-histories
上一篇下一篇

猜你喜欢

热点阅读