Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why do git reset commit + git push cause tip of current branch to go behind remote?

I wanted to undo a couple minor changes on my repo. I decided to go back two commits, and did

git reset --hard <commit>

and

git push -f

Everything went through fine. But when I pushed to heroku, I got an error about how some refs weren't pushed, and then this explanation:

Updates were rejected because the tip of your current branch is behind its remote counterpart. Merge the remote changes (e.g. 'git pull') before pushing again.

Every time I go back to a previous commit, I wind up with a detached HEAD or with the tip behind remote. This prevents me from pushing to git or heroku. Why? How do I get around this? What is the proper list of commands to follow so that this does not cause interference in the future?

like image 406
calyxofheld Avatar asked Oct 20 '22 13:10

calyxofheld


1 Answers

I think that heroku is not allowing you to rewrite the history. When you are working on remote branches you shouldn't use reset or rebase. By using

git revert HEAD~2..HEAD

2 new commits will be created reverting the changes from the last 2 commits. This also prevents merging conflicts for your co-workers.

like image 125
Mihai238 Avatar answered Oct 23 '22 04:10

Mihai238