Undo a merge you haven't pushed
Careful: rewrites history
Short answer
Right after the merge, run git reset --keep HEAD~1: your branch goes back to where it was before the merge.
Only if the merge isn't pushed. Pushed? See Undo a pushed merge. Still in the middle of a merge with conflicts? Use git merge --abort instead.
The commands, one by one
- 1
git reset --keep HEAD~1HEAD~1of a merge commit is the commit your branch was on before you merged. The merged branch itself isn't touched, so you can merge it again later. - 2
git log --onelineThe merge commit and the branch's commits are gone from
main.