Search code examples
gitgithubheroku

Updates were rejected because the tip of your current branch is behind its remote counterpart. Integrate the remote changes


One of the devs on our team has been committing and pushing directly to our heroku repo without pushing to github first and using it for version control.

I've gotten the master on github and my local synced with each and up-to-date, and this is the version of the codebase I want to be in production. When I try git push heroku master I get the following error:

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.

What is the best way to get our codebase on heroku in-sync with github's? Would it just be a git push heroku master -f ?

Thanks in advance for any help


Solution

  • If you are willing to throw away everything the dev did on heroku, then push with force to heroku. This will cause heroku to match exactly, both as to state and as to history, the branch that you push.

    Actually, any push causes the remote to match exactly, as to state and history, the branch that you push. But Git doesn't let you push to a remote unless the result would be a "fast-forward". In your case, there have been commits on heroku that you don't have, so the result would not be a "fast-forward" and Git blocks the push. Using force overcomes that block.