Git: Abort a Merge
Last updated
If a git merge runs into conflicts and you'd rather back out than resolve them, git merge --abort cancels the merge and restores your branch to exactly the state it was in before you started. It's the clean escape hatch from a merge that's gone sideways.
For a merge that already completed, you undo it differently - see below. Try these in the terminal playground - a real shell in your browser.
Syntax
| Command | What it does |
|---|---|
git merge --abort | Cancel a conflicted merge, restore pre-merge state |
git reset --merge | Older equivalent - abort and reset the merge |
git merge --quit | Leave the merge but keep the working tree as-is |
Undoing a merge that already finished
Different from aborting - the merge commit already exists.
| Situation | Command |
|---|---|
| Merge is local, not pushed | git reset --hard ORIG_HEAD |
| Merge is already pushed | git revert -m 1 <merge-hash> |
Git abort merge FAQ
How do I cancel a merge in progress?
Run
git merge --abort. If a merge stopped because of conflicts and you don't want to resolve them, this cancels the whole operation and returns your branch and working tree to exactly how they were before the merge started.What's the difference between git merge --abort and git reset --merge?
They do essentially the same job - cancel an in-progress merge and restore the pre-merge state.
git merge --abort is the modern, purpose-built command; git reset --merge is the older way that still works. Prefer git merge --abort for clarity.How do I undo a merge that already completed?
That's not an abort, since the merge commit already exists. If the merge is only local,
git reset --hard ORIG_HEAD moves the branch back to where it was before the merge - it works after a fast-forward too, where HEAD~1 would not. It discards uncommitted work, so check git status first. If you've already pushed the merge, use git revert -m 1 <merge-hash> to reverse it without rewriting shared history.Will aborting a merge lose my other changes?
git merge --abort restores the state from just before the merge, so the merge's changes are discarded, but your own committed work is intact. If you had uncommitted changes before starting the merge, commit or stash them first - abort restores the pre-merge commit state.Can I practice this online?
Yes. Open the terminal playground to run
git merge --abort in a real shell in your browser - nothing to install. Coddy's free interactive Git course also covers merging and resolving conflicts step by step.