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

个人GitHub仓库Push报错求助:non-fast-forward拒绝推送

解决Git推送non-fast-forward错误(个人仓库无他人更新场景)

你遇到的错误信息:

! [rejected]        HEAD -> main (non-fast-forward)
error: failed to push some refs to 'https://pagelocation'
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.

针对个人仓库无他人提交的情况,按以下步骤排查解决:

1. 确认分支跟踪状态

先检查本地main分支是否正确跟踪远程origin/main:

git branch -vv

如果输出里main分支没有关联origin/main,重新设置跟踪关系:

git branch -u origin/main main

2. 重置本地分支与远程同步(先备份修改)

确保本地修改已备份后,执行以下操作:

  • 暂存未提交的修改:
git stash
  • 把本地main分支强制重置为远程分支的状态:
git reset --hard origin/main
  • 恢复暂存的修改:
git stash pop
  • 重新提交并推送:
git add .
git commit -m "提交描述"
git push origin main

3. 检查Quarto自动推送配置

如果使用Quarto发布网站,可能Quarto在渲染过程中自动向远程推送了生成的静态文件,导致远程分支有本地未同步的提交。检查_quarto.yml中的publish配置,确认是否开启了自动推送,避免和本地手动提交冲突。

4. 修复本地Git refs异常

如果以上方法无效,可能是本地Git的分支引用损坏:

# 删除本地main分支的引用文件
rm .git/refs/heads/main
# 拉取远程分支信息
git fetch origin
# 重新检出main分支
git checkout main

之后重新提交并尝试推送。

内容的提问来源于stack exchange,提问作者Jimmy2Goons

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 14:17:15