Finish or cancel an unfinished Git merge

Resolve the MERGE_HEAD exists error by completing the current merge or aborting it without manually deleting Git state.

Best practices
Illustration of Git commit history and recovery

You have not concluded your merge (MERGE_HEAD exists) means Git is still recording an in-progress merge. It may be waiting for conflict resolutions, or the merge may simply have been started with --no-commit. Finish that operation or cancel it before starting another pull or merge.

Complete the merge

git status
git diff --name-only --diff-filter=U

Read each conflict and edit the file to the intended result. Do not remove conflict markers mechanically without understanding which changes belong. Stage only the resolutions you have reviewed:

git add -- path/to/resolved-file
git diff --cached
git status
git commit

For a resolution that deletes a file, use git rm -- path/to/file. Once every unmerged path is resolved, git commit completes the merge; git merge --continue is another option. If Git says all conflicts are fixed but the merge is still in progress, the commit step is what remains.

Cancel the merge

git merge --abort

This attempts to reconstruct the pre-merge state. It cannot always recover uncommitted edits that existed before the merge and were then changed further. If you have valuable work in the current conflict resolution, copy it somewhere safe before aborting. Starting merges with a clean working tree makes recovery much simpler.

Understand the state marker

MERGE_HEAD records the commit or commits being merged. In linked worktrees, .git may be a file rather than a directory; git rev-parse --git-path MERGE_HEAD locates the relevant state path.

Do not delete the marker as a repair. Removing it does not resolve conflicts or restore the index, and can lose the merge-parent relationship when you later commit. Use the operation's normal continue or abort command.

Similar errors in other operations

A paused cherry-pick or revert has its own state. Inspect git status and use git cherry-pick --continue / --abort or git revert --continue / --abort as appropriate. Revert and cherry-pick do not both use CHERRY_PICK_HEAD.

An editor's three-way merge view can help inspect the base and both sides. Regardless of the tool, stage the resolved files, review the final diff, and run relevant tests before committing.

References: git merge, git status, and Git repository layout.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting