当我试图将我的代码推送到GitHub时,我遇到了一些问题。

Pushing to git@github.com:519ebayproject/519ebayproject.git
To git@github.com:519ebayproject/519ebayproject.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:519ebayproject/519ebayproject.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

我还没有在存储库中推入任何东西,那么为什么我需要拉出一些东西呢?


当前回答

我遇到了同样的问题,结果是我在一个不同的(本地)分支上,而不是我认为的,正确的本地分支在远程提交时落后了。

我的解决方案:签出正确的分支,从其他本地分支中选择提交,git拉和git推

其他回答

有些人可能会遇到这个错误,因为Git不知道您要推哪个分支。

如果您的错误消息还包括

error: failed to push some refs to 'git@github.com:jkubicek/my_proj.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. If you did not intend to push that branch, you may want to
hint: specify branches to push or set the 'push.default' configuration
hint: variable to 'current' or 'upstream' to push only the current branch.

那么你可能想要遵循Jim Kubicek的提示,将Git配置为只推送当前分支,将默认分支设置为当前分支。

git config --global push.default current

只是有同样的问题,但在我的情况下,我在遥控器上输入了错误的分支。所以,这似乎是这个问题的另一个来源……仔细检查你是否推到了正确的分支。

造成这个问题的另一个原因(显然不太常见)是……

当我进行推送时,我的服务器延迟了大约12个小时

我在服务器上配置了NTP同步我的时钟。

我执行了一个新的git推送,导致了这篇文章中讨论的错误。

另一种选择:在本地将分支重命名为新的名称。

然后,您将能够将其推送到远程存储库,例如,如果这是您保持副本(备份)并确保没有丢失任何东西的方法。

您可以获取远程分支以获得本地副本,并检查(i)远程所拥有的(使用旧的分支名称)和(ii)您所拥有的(使用新分支名称)之间的差异,并决定要做什么。由于您一开始就没有意识到远程的差异(因此出现了问题),因此简单地合并或强制在某个地方进行更改就太残酷了。

查看差异,选择您想要处理的分支,从其他分支中选择您想要的更改,或者恢复您不想要的分支上的更改,等等。

然后,您应该能够决定是否要将干净的版本强制到远程服务器上,或者添加新的更改,或者其他什么。

使用git拉https://github.com/username/repository 这是因为Github和远程存储库不同步。如果你拉了repo,然后Push,一切都会同步,错误就会消失。

`