1

I pushed onto my branch with git push origin branch. I then realized that I made a small mistake in this commit. I didn't want to revert because a large part of the commit was correct, only a small change was needed. Instead of reverting, I git reset --soft <previous-commit> such that I did not lose my staged files. I then committed the fix to the small mistake. Unfortunately, I realized the hard way that I couldn't push after doing so, since the most recent commit on my local and remote were out of sync.

For instance.

A-B-C-D // Local, before git reset --soft
A-B-C-D // Remote
A-B-C   // Local, after git reset --soft
A-B-C-E // Local, after new commit.

What should I be doing in this situation so that remote reflects local? What would git push -f origin branch do in this case?

Thanks

  • Note : you don't have one `HEAD` for each branch, only one for each repo. – Romain Valeri Feb 27 '20 at 14:28
  • @RomainValeri Thanks for the correction, I changed the title of the question. –  Feb 27 '20 at 14:28
  • Force the push, if you are really sure it's ok (`git push -f blablabla`). – Enlico Feb 27 '20 at 14:30
  • Does this answer your question? [How do I properly force a Git push?](https://stackoverflow.com/questions/5509543/how-do-i-properly-force-a-git-push) – Enlico Feb 27 '20 at 14:32

0 Answers0