错误:无法将一些引用推送到'https://github.com/XXXXXXXXX.com

时间:2020-09-12 09:29:40

标签: git github push git-push git-pull

$ git push -u origin master
To https://github.com/XXXXXXXXX.com/FirstRepo.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/XXXXXXXXX.com/FirstRepo.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.

我今天是第一次使用github,我已经检查了其他答案,其中只有一个似乎可行,并且正在使用'git push origin master --force',但是这样做是删除所有其他提交。所以任何人都可以告诉我解决方案。

2 个答案:

答案 0 :(得分:1)

如果您的local分支位于remote分支的后面,并且在其上面有一些提交,则可以通过运行以下命令来解决问题。

$ git pull origin master --rebase
$ git push origin master

注意事项:如果仅运行git pull而没有--rebase,则它将添加您可能不希望的merge提交。

答案 1 :(得分:1)

只需在终端中运行此代码。

git pull origin master --allow-unrelated-histories

或者如果您使用主分支运行此代码

git pull origin main --allow-unrelated-histories