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

推送Unity项目至GitHub私有仓库遇non-fast-forward错误求助

解决Git推送Unity项目至GitHub私有仓库的non-fast-forward错误

你执行的终端命令:

git add .
git commit -m "commit"
git remote add origin "myrepolink"
git push -u origin "first_part"

遇到的错误信息:

! [rejected] first_part -> first_part (non-fast-forward)
error: failed to push some refs to 'myrepolink'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

原因

远程分支first_part存在本地没有的提交记录,本地分支落后于远程分支,导致推送被拒绝。

解决方案

方案1:合并远程内容(推荐,安全不丢失数据)

  1. 拉取远程分支的最新内容并合并到本地:
    git pull origin first_part
    
  2. 如果拉取时出现冲突(比如Unity的场景文件、.meta文件冲突),手动打开冲突文件解决矛盾,之后执行:
    git add .
    git commit -m "解决远程分支合并冲突"
    
  3. 再次推送:
    git push -u origin first_part
    

方案2:强制覆盖远程分支(谨慎使用,会丢失远程现有内容)

如果你确认远程分支的内容不需要保留,可以强制推送覆盖:

git push -u origin first_part --force

Unity项目额外注意事项

  • 确保配置了正确的.gitignore文件,排除Library、Temp、obj等Unity自动生成的文件夹,减少不必要的文件冲突。
  • 推送前用git status检查待提交文件,避免误提交冗余内容。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 01:20:05