Git
Merge Conflict
Version Control
MERGE_HEAD
Git Troubleshooting

You have not concluded your merge MERGE_HEAD exists

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The MERGE_HEAD exists message means Git detected an unfinished merge operation. Until you resolve or abort that merge, Git blocks other operations that change history. The fix is to choose one path intentionally: finish the merge or roll back safely.

What MERGE_HEAD Represents

When you run git merge, Git writes merge state files in .git. MERGE_HEAD stores the commit being merged into your current branch.

As long as this file exists, Git assumes merge resolution is still in progress. That is why commands such as git pull, another merge, or some rebases fail until state is cleared.

First check repository status:

bash
git status

This usually shows unmerged paths or pending merge commit instructions.

Path 1: Complete the Merge

Choose this path if the merge is intended and you want merged history.

List unresolved files:

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

Resolve each conflict marker in those files, then stage changes:

bash
git add path/to/file

After all conflicts are staged, finalize merge commit:

bash
git commit

At this point Git removes merge state files and normal workflow resumes.

Path 2: Abort the Merge

Choose this path if merge was accidental or should be retried later.

bash
git merge --abort

This tries to restore branch, index, and working tree to pre-merge state.

If abort fails because of additional edits, protect local work first:

bash
git stash push -u -m "save before merge abort"
git merge --abort

Later you can inspect and reapply stash selectively.

Verify Merge State Is Cleared

Do not assume cleanup succeeded. Confirm explicitly.

bash
git status
git rev-parse -q --verify MERGE_HEAD

Expected behavior:

  • status no longer reports merge in progress
  • 'MERGE_HEAD verification returns no hash'

Also review recent history:

bash
git log --oneline --graph --decorate -10

You should see either a new merge commit or no merge event if aborted.

Sometimes merge state is not the only active operation. Check for rebase or cherry-pick state as well.

bash
git rev-parse -q --verify REBASE_HEAD
git rev-parse -q --verify CHERRY_PICK_HEAD

Resolve one operation at a time. Mixing recovery commands across states can make repository history harder to repair.

Useful Conflict Resolution Commands

For large merges, targeted commands speed up conflict handling.

Accept current branch version for one file:

bash
git checkout --ours path/to/file

Accept incoming branch version:

bash
git checkout --theirs path/to/file

Launch configured merge tool:

bash
git mergetool

Use these carefully and always rerun tests after resolution.

Prevention Practices

You can reduce unfinished merge incidents with simple habits:

  • start merges from a clean working tree
  • avoid task switching mid-conflict
  • keep branches short-lived and merge frequently
  • run tests before and after merge operations
  • communicate large merges to teammates in advance

Process discipline often matters more than tooling.

Common Pitfalls

  • Running git pull repeatedly without completing current merge.
  • Staging only some conflicted files and expecting merge commit to work.
  • Manually deleting internal merge files instead of using Git commands.
  • Aborting without preserving local edits that might still be needed.
  • Starting rebase while merge state remains unresolved.

Summary

  • 'MERGE_HEAD exists means an unfinished merge is blocking further operations.'
  • You must either finish conflict resolution and commit or abort the merge.
  • Verify cleanup by checking git status and MERGE_HEAD presence.
  • Handle related states such as rebase and cherry-pick separately.
  • Good merge hygiene prevents repeated interrupted-merge situations.

Course illustration
Course illustration

All Rights Reserved.