[英]Getting an error pushing to github - Updates were rejected because a pushed branch tip is behind its remote
I am having a problem pushing to a different heroku remote.我在推送到不同的 heroku 遥控器时遇到问题。
To check myself I renamed my entire project directory to _backup and then:为了检查自己,我将整个项目目录重命名为 _backup,然后:
git clone account/repo_name
git remote add repo2 git@heroku.com:repo2.git
git push repo2 branch_abc:master
But I am still getting但我仍然得到
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.
I have tried several SO questions and answers but not worked for me, still getting the error regardless.我已经尝试了几个 SO 问题和答案,但对我不起作用,无论如何仍然出现错误。
If you don't care about what's currently in repo2 and are confident that totally overwriting it is ok then you can use:如果您不关心当前在 repo2 中的内容并且确信完全覆盖它是可以的,那么您可以使用:
$ git push -f git@heroku.com:<heroku repo name>.git
Remember though that push -f
can wipe out other developers changes if they were posted since you last pulled from the repo... so always use with extreme caution on multi-developer teams!请记住,
push -f
可以清除自上次从存储库中拉出后发布的其他开发人员更改……因此,在多开发人员团队中始终要格外小心!
In this case heroku is always downstream and github is where the code is managed and maintained so this makes push -f
on heroku a safer option that it would otherwise be.在这种情况下,heroku 始终位于下游,而 github 是管理和维护代码的地方,因此这使得在 heroku 上使用
push -f
成为一个更安全的选择,否则将是。
I am always a big fan of using git pull --rebase and then git push origin master .我一直是使用 git pull --rebase 然后使用 git push origin master 的忠实粉丝。 A couple of the places I have worked since a lot of places do not allow a push -f (especially places that use bitbucket).
因为很多地方都不允许 push -f(尤其是使用 bitbucket 的地方),所以我工作过的几个地方。
git pull --rebase
git push origin master
The rebase will apply your changes after those already to the remote (online website). rebase 将在那些已经应用于远程(在线网站)的更改之后应用您的更改。 This video literally goes over your exact issue and solves it using git pull --rebase https://youtu.be/IhkvMPE9Jxs?t=10m36s
该视频从字面上详细介绍了您的确切问题并使用 git pull --rebase https://youtu.be/IhkvMPE9Jxs?t=10m36s解决它
If you pull the other repo first:如果您先拉另一个回购:
git pull repo2 git pull repo2
This will merge in the other repos's changes which you can add and commit.这将合并到您可以添加和提交的其他存储库的更改中。
Then you can push the repo back.然后你可以将回购推回去。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.