How to Undo a Git Merge
The right way to undo a Git merge depends on whether Git is still merging or has already completed the operation—and whether you have shared the result. Use git merge --abort for a merge in progress. For a completed merge, choose between moving a private branch back and creating a revert commit on shared history.
First, check whether the merge is still in progress
Check the repository status before choosing a command:
git status
git log --oneline --graph -5If git status says a merge is in progress, it has not been committed yet. If the merge commit already appears in git log, use the section for completed merges. A fast-forward merge may complete without creating a merge commit, so look at the branch history and status rather than relying only on whether a merge commit exists.
Abort a merge that is still in progress
To stop the current merge and return to the state from before it began, run:
git merge --abortThis is the usual choice when merge conflicts are difficult or you started the wrong merge. If you had uncommitted changes before merging, Git may not always be able to reconstruct them cleanly. That is why checking and saving valuable work before starting a merge matters. Verify the result with git status.
Undo a completed merge on a private local branch
If the merge is complete but has not been pushed or shared, you may move the branch back to its pre-merge commit. First inspect the current branch, working tree, and the previous tip Git recorded:
git status
git log --oneline --decorate -5
git show --no-patch --oneline ORIG_HEADORIG_HEAD often points to where the branch was before the merge, but later Git operations can change it. Confirm the commit is actually the pre-merge tip. If it is, and there is no valuable uncommitted work, you can reset to it:
git reset --merge ORIG_HEADThis moves the current branch back and updates the index and working tree. If your branch has progressed since the merge, use the verified pre-merge commit ID instead of assuming ORIG_HEAD is correct. Consider making a backup branch first. Avoid git reset --hard unless you explicitly intend to discard local changes.
Undo a merge that has already been pushed
If teammates may have based work on the pushed result, do not move the shared branch backward. Create a new commit that reverses the merge instead. For a merge commit, see how to revert a merge commit. A fast-forward merge has no merge commit, so identify the appropriate commit or commits to revert rather than using a merge revert command.
If the merge was pushed but nobody else has used the branch, coordinate with your team before rewriting it. Reverting is the safer default for shared history because it preserves existing commit IDs.
What if the merge was fast-forwarded?
A fast-forward moves the branch pointer forward without creating a merge commit. If it is private and you have verified the previous branch tip, reset to that commit as described above. If it is shared, do not reset the branch just to undo the update; revert the appropriate changes with new commits. The exact revert depends on which commits were introduced and whether you want to keep any of them.
Frequently asked questions
Does git merge --abort undo a merge commit?
No. It cancels a merge that is still in progress. For an already completed merge, reset a private branch to its verified pre-merge commit or create a revert commit if the result is shared.
Is git reset --hard ORIG_HEAD safe?
It can discard uncommitted changes, and ORIG_HEAD may not point to the commit you expect. Inspect the target first and prefer a non-destructive approach unless you have verified both the commit and the work you are willing to lose.