我昨天还能推,现在却推不动了。

当我使用git push origin master时,我得到一个错误:

$ git remote -v
origin  https://github.com/REDACTED.git (fetch)
origin  https://github.com/REDACTED.git (push)

$ git push origin master
Username for 'https://github.com': REDACTED
Password for 'https://REDACTED@github.com':
To https://github.com/REDACTED.git
! [rejected]         master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/REDACTED.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获取原点 获取在线存储库的更新 $ git合并起源分支 #将在线更新与本地工作合并 或者,你可以简单地使用git pull一次执行这两个命令: $ git拉起源分支 #获取在线更新,并将其与您的本地工作合并

其他回答

我得到了这个错误,因为我试图在没有提交的情况下进行push 所以试着

Git添加。 Git commit -m "message" Git push -f

然后它对我很有效

最好使用rm -rf .git/hooks,然后尝试git push

对于Sourcetree用户

首先进行初始提交,或者确保没有任何未提交的更改。然后在Sourcetree的一侧有一个“REMOTES”。右键单击它,然后单击“推到原点”。好了。

Try:

git push -f origin master

这样问题就解决了。

根据@Mehdi的评论,关于-force push有一个澄清:上面的Git命令只在第一次提交时安全工作。如果之前已经有提交,拉请求或分支,这将重置所有它,并将其从零设置。如果是这样,请参考@VonC的详细回答,以获得更好的解决方案。

在我的案例中,问题是(奇怪的是)没有一个叫做master的分支。我从GitHub获取了这个存储库。