Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
838 views
in Technique[技术] by (71.8m points)

git - 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.

To check myself I renamed my entire project directory to _backup and then:

git clone account/repo_name

git remote add repo2 [email protected]: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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you don't care about what's currently in repo2 and are confident that totally overwriting it is ok then you can use:

$ git push -f [email protected]:<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!
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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...