Git: You have not concluded your merge (MERGE_HEAD exists)

avatar
Borislav Hadzhiev

Last updated: Apr 5, 2024
5 min

banner

# Git: You have not concluded your merge (MERGE_HEAD exists)

The Git error "You have not concluded your merge (MERGE_HEAD exists)" occurs when:

  1. You use the git pull command but get merge conflicts.
  2. You use the git pull command again before having resolved all merge conflicts.

To solve the error, undo the merge, pull again and resolve the merge conflicts fully.

you have not concluded your merge merge head exists

Here is the complete stack trace:

shell
error: You have not concluded your merge (MERGE_HEAD exists). hint: Please, commit your changes before merging. fatal: Exiting because of unfinished merge.

The steps to solving the error are:

  1. Return to the state before you started the merge with the git merge --abort command.
shell
git merge --abort

undo the merge

The command simply undoes the merge operation.

If you get the error "Entry 'example.txt' not uptodate. Cannot merge. fatal: Could not reset index file to revision 'HEAD'." when issuing the git merge --abort command, use the git add . command first.

shell
git add . git merge --abort

entry not uptodate cannot merge

  1. Use the git pull command to pull the changes from the remote.
shell
git pull origin master

Make sure to replace master with the name of your remote branch.

git pull from remote

  1. Resolve the merge conflict(s).

You can issue the git mergetool command to open an interactive GUI that helps you resolve the merge coflicts.

shell
git mergetool

open git mergetool

In my case, the git mergetool command opens VS Code because I've configured it as my Git mergetool.

If you also want to set up VS Code as your Git editor, difftool and mergetool, check out my other article:

You can click on the Accept or Ignore buttons to accept the local or remote changes.

resolve merge conflicts

  1. Once you have resolved the merge conflict(s), add and commit your changes.
shell
git add . git commit -m 'your commit message'

add and commit the changes

You must add your changes to the staging area and commit them before issuing the git pull command.

If you resolve all merge conflicts and add the changes to the staging area with the git add . command, but forget to commit, you would get the error again and you'd have to undo the merge.

  1. After you have added your files and committed the changes, issue the git pull command.
shell
git pull origin master

pull works after fixing merge conflicts

Make sure to replace master with the name of your remote branch.

# Don't forget to commit after staging your changes

It is very important to note that you would get the error if:

  1. You git pull from the remote and get merge conflicts.
  2. You resolve all merge conflicts.
  3. You add the updated files to the staging area with git add ..
shell
# ⛔️ Incorrect (forgot to commit) git add . git pull origin master
  1. You issue the git pull command again before committing your changes.

This flow causes the error because we forgot to commit the changes after issuing the git add . command.

At this point, we haven't concluded the merge and trying to pull from the remote causes the error.

shell
# ✅ Correct (committed before pulling) git add . git commit -m 'your message' git pull origin master

If you have staged or unstaged changes that you haven't committed, you will be able to see them when issuing the git status command.

shell
git status

check for uncommitted changes

The screenshot shows that I have changes that I haven't staged (with git add .) and changes that I haven't committed.

After you stage and commit the changes, your working tree should be clean.

shell
git add . git commit -m 'your message' git status

working tree clean after committing

If you see the message that there is nothing to commit and the working three is clean, you can issue the git pull command without getting the error.

# Deleting the contents of the .git/MERGE directories

If the error persists even after you have resolved all merge conflicts:

  1. Open your terminal in your project's root directory (where the .git folder is located).

  2. Delete the contents of the .git/MERGE* directories.

Note: if you are on Windows, issue the command in Git Bash or manually delete the MERGE* folders in your .git directory.

shell
rm -rf .git/MERGE*

Make sure you have staged and committed your changes.

shell
git add . git commit -m 'your commit message'

add and commit the changes

Issue the git pull command again.

shell
git pull origin master

pull works after fixing merge conflicts

Make sure to replace master with the name of your remote branch.

# Using the --continue flag of the git merge command

If the error persists, try to issue the git merge command with the --continue flag.

shell
git merge --continue

The continue flag is used to finish a merge after resolving conflicts.

The command checks if there is an interrupted merge in progress before calling the git commit command.

# Taking the changes from the remote

If you simply want to overwrite your local branch with the changes from the remote branch, use the git reset --hard command.

Note that if you use the git reset --hard command, any changes you've made locally to tracked and untracked files will be discarded.

shell
# overwrite local changes with the changes from the remote git reset --hard origin/master

reset with hard flag

Alternatively, you can save your local changes and apply them on top of the remote branch:

# Conclusion

To solve the "You have not concluded your merge (MERGE_HEAD exists)" Git error:

  1. Use the git merge --abort command to undo the merge.
  2. Use the git pull command to pull the changes from the remote.
  3. Resolve the merge conflict(s).
  4. Stage and commit your changes with the git add . and git commit commands.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.