You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitLab推送文件夹报错master -> master (non-fast-forward)如何解决?

Git 推送non-fast-forward错误解决方案

错误说明

触发报错的原始返回信息如下:

[Rejected] master -> master (non-fast-forward)
Error: failed to push some refs to 'https://gitlab.com/sen-flutter.git'
Hint: Updates were rejected because the tip of your current branch is behind
Hint: Its remote counterpart. Integrate the remote change (e.g. 'git pull ...') before pushing again.
Hint: See the 'Note about fast-forwards' in git push --help' for details

核心原因

本地当前操作分支的提交记录版本落后于远程对应分支,远程分支存在本地没有的提交内容,Git默认禁止直接覆盖推送。

可行解决方案

场景A:需保留远程分支现有内容

适用于远程仓库有其他协作者提交的内容、或远程初始化生成的README/LICENSE等文件需要保留的情况

  • 拉取远程最新内容并rebase合并到本地分支:
    git pull origin master --rebase
    若合并过程中出现文件冲突,先手动编辑冲突文件完成内容修正,再执行git add <冲突文件路径>,之后运行git rebase --continue完成合并流程
  • 合并完成后执行正常推送:
    git push origin master

场景B:无需保留远程分支现有内容

适用于远程为新建空仓库、远程所有内容均可被本地内容覆盖的情况,注意:该操作会清空远程对应分支的所有现有提交记录,请确认后执行

  • 执行强制推送命令:
    git push origin master -f

内容的提问来源于stack exchange,提问作者Handika Pramudya Putra

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.07 01:36:03