Git命令报错合集

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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 221,548评论 6 515
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 94,497评论 3 399
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 167,990评论 0 360
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,618评论 1 296
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,618评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 52,246评论 1 308
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,819评论 3 421
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,725评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,268评论 1 320
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,356评论 3 340
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,488评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 36,181评论 5 350
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,862评论 3 333
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,331评论 0 24
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,445评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,897评论 3 376
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,500评论 2 359

推荐阅读更多精彩内容