获取错误推送到github - 更新被拒绝,因为推送的分支提示在其远程后面

时间:2013-01-30 16:49:07

标签: git heroku

我在推送到另一个Heroku遥控器时遇到问题。

要检查自己,我将整个项目目录重命名为_backup,然后:

git clone account/repo_name

git remote add repo2 git@heroku.com:repo2.git

git push repo2 branch_abc:master

但我还是得到了

hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge the remote changes
hint: (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

我已经尝试了几个SO问题和答案,但不适合我,仍然得到错误。

3 个答案:

答案 0 :(得分:35)

如果您不关心当前处于repo2中的内容并确信完全覆盖它是正常的那么您可以使用:

$ git push -f git@heroku.com:<heroku repo name>.git

请记住,push -f 可以消除其他开发人员的更改,如果他们上次从回购中删除后发布了...所以请始终谨慎使用多开发人员团队!
在这种情况下,heroku总是在下游,而github是管理和维护代码的地方,因此这使得heroku上的push -f成为一个更安全的选项。

答案 1 :(得分:8)

我总是喜欢使用git pull --rebase然后git push origin master。我工作过的几个地方,因为很多地方不允许推-f(尤其是使用bitbucket的地方)。

git pull --rebase 
git push origin master

rebase将在已经更改到远程(在线网站)之后应用您的更改。这段视频完全解决了您的确切问题,并使用git pull --rebase https://youtu.be/IhkvMPE9Jxs?t=10m36s

解决了这个问题

答案 2 :(得分:5)

如果你先拉另一个回购:

git pull repo2

这将合并到您可以添加和提交的其他repos的更改中。

然后你可以推回回购。

相关问题