How to: Cancel a Git merge

If you ever accidentally initiate a merge (between the wrong branches, etc) and get a bunch of unexpected conflicts you might want to cancel the merge.

Just do this (assuming your Git version is 1.7.4 or greater):

git merge --abort

You should now be back at a stage before the merge started.

For older Gits

If you're on an older Git (but newer than version 1.6.1) you can use

git reset --merge

If you're stuck on even older version of Git you can try

git reset --hard HEAD

and you'll be taken back to the last valid commit (HEAD) before the merge started.