All fixes

Help, I merged the wrong branch

Undo a merge you did not mean to make, before or after pushing it.

What Git says~/my-app
git merge feature/experiment
Merge made by the 'ort' strategy.

The fix

  1. git reset --hard ORIG_HEAD

    Puts your branch back where it was before the merge. Also resets uncommitted changes to tracked files.

    Discards uncommitted changes
What happens to your historygit reset --hard ORIG_HEAD
BeforeABFMHEADmainfeature/experiment
AfterABFMHEADmainfeature/experiment

Why this works

Before a merge, Git saves where your branch was as ORIG_HEAD, so resetting to it undoes the merge in one go. Do it straight away: the next reset, rebase or pull overwrites ORIG_HEAD. After pushing, revert the merge commit instead. One catch: Git then considers the branch merged, so if you want it in for real later, revert the revert first.