错误:无法将一些参考推送到“https://github.com/XXXXXXXXX.com”

P Y*_*hvi 1 git push github git-pull git-push

$ 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.
Run Code Online (Sandbox Code Playgroud)

我今天第一次使用 github,我已经检查了其他答案,其中只有一个似乎有效,那就是使用“git push origin master --force”,但通过这样做,它会删除所有其他提交。那么有人可以告诉我这个问题的解决方案吗?

Mas*_*man 5

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

$ git pull origin master --rebase
$ git push origin master
Run Code Online (Sandbox Code Playgroud)

注意:如果您只在git pull没有 的情况下运行--rebase,那么它将添加merge您可能不想要的提交。