我用主分支创建了一个存储库,当我准备推送代码时,我不小心创建了另一个分支 -
master
。现在,当我尝试合并 2 个分支时,我收到消息:
我也收到提示:
另外,当我尝试
git push
进入主目录时,我收到错误:
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/ATFUSA/ATFUSA.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.
尝试:
git pull
git checkout main
git merge master --allow-unrelated-histories
git push <upstream> main -f
显然,将
<upstream>
替换为您的存储库。
这里的关键是
--allow-unrelated-histories
。默认情况下,git 不允许您合并两个完全不同的分支,以防止错误地合并两个不同的项目,但这将覆盖该保护。 Push 命令中的 -f
是强制推送,然后确保 GitHub 不会拒绝推送。请参阅文档了解更多信息。