git 无法push远程仓库 Note about fast-forwards 问题解决

  git push 远程仓库时,出现以下类似错误,'Note about fast-forwards' in 'git push --help' for details.

To https://github.com/SeshinWei/django.git

! [rejected]        master -> master (non-fast-forward)

error: failed to push some refs to 'https://github.com/SeshinWei/django.git'

hint: Updates were rejected because the tip of your current branch is behind

hint: its remote counterpart. Integrate the remote changes (e.g.

hint: 'git pull ...') before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.

错误:non-fast-forward

远程仓库:origin

远程分支:master

本地分支:master

完整报错代码可能是这样的:

Thereisno tracking informationforthe current branch.Please specify which branch you want to mergewith.See git-pull(1)fordetails.    git pull If you wish to set tracking informationforthis branch you can do sowith:    git branch --set-upstream-to=origin/ master

原因是没有指定本地master分支和远程origin/master的连接,这里根据提示:

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

解决方案:因为远程仓库新建时,有LIENCE,由于本地仓库和远程仓库有不同的开始点,也就是两个仓库没有共同的commit出现,无法提交,此时我们需要allow-unrelated-histories。也就是我们的 pull 命令改为下面这样的:

git pull origin master --allow-unrelated-histories

如果设置了默认分支,可以这样写:

git pull --allow-unrelated-histories

然后 git push 就可以了。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Lesson 3: Using GitHub to Collaborate 3.1 Creating a GitH...
    赤乐君阅读 11,324评论 3 11
  • origin websiteComparing WorkflowsCentralized Workflow Fea...
    伍帆阅读 3,452评论 0 0
  • 首先确定电脑安装了git 输入git会产生提示: 如果没有安装,那么就网上搜索下载完成安装. 可以使用命令行安装,...
    元宇宙协会阅读 9,906评论 1 9
  • 题目是一本书的书名,一本被名字耽误的书。这本书我在初中时第一次看见,我的虐文启蒙书,高中时又被反复挑出来看...
    Gusubedy阅读 3,567评论 0 1
  • 贝多芬降E大调第三交响曲,标题为《英雄交响曲,为纪念一位伟人而作》。对,我就是伴着这样的背景音乐,写出下面的文字的...
    二十五点一刻阅读 3,465评论 0 0