Last updated: Apr 5, 2024
Reading time·5 min
The Git error "You have not concluded your merge (MERGE_HEAD exists)" occurs when:
git pull
command but get merge conflicts.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.
Here is the complete stack trace:
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:
git merge --abort
command.git merge --abort
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.
git add . git merge --abort
git pull
command to pull the changes from the remote.git pull origin master
Make sure to replace master
with the name of your remote branch.
You can issue the git mergetool
command to open an interactive GUI that helps
you resolve the merge coflicts.
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.
git add . git commit -m 'your commit message'
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.
git pull
command.git pull origin master
Make sure to replace master
with the name of your remote branch.
It is very important to note that you would get the error if:
git pull
from the remote and get merge conflicts.git add .
.# ⛔️ Incorrect (forgot to commit) git add . git pull origin master
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.
# ✅ 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.
git status
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.
git add . git commit -m 'your message' git status
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.
If the error persists even after you have resolved all merge conflicts:
Open your terminal in your project's root directory (where the .git
folder
is located).
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.
rm -rf .git/MERGE*
Make sure you have staged and committed your changes.
git add . git commit -m 'your commit message'
Issue the git pull
command again.
git pull origin master
Make sure to replace master
with the name of your remote branch.
--continue
flag of the git merge
commandIf the error persists, try to issue the git merge
command with the
--continue
flag.
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.
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.
# overwrite local changes with the changes from the remote git reset --hard origin/master
Alternatively, you can save your local changes and apply them on top of the remote branch:
To solve the "You have not concluded your merge (MERGE_HEAD exists)" Git error:
git merge --abort
command to undo the merge.git pull
command to pull the changes from the remote.git add .
and git commit
commands.You can learn more about the related topics by checking out the following tutorials: