How do I cancel a git merge?

Use git-reset or git merge --abort to cancel a merge that had conflicts.

# Reset all the changes back to the last commit.
# Note: This cannot be reverted!
$ git reset --hard HEAD

# OR
$ git merge --abort

Please note that all the changes will be reset, and this operation cannot be reverted, so make sure to commit or git-stash all your changes before you start a merge.

Uncommited changes may also create difficulties when trying to cancel the merge:

Warning: Running git merge with non-trivial uncommitted changes is discouraged: while possible, it may leave you in a state that is hard to back out of in case of a conflict.

For a complete list of all the options check the official Git docs: git-reset, git-merge.