日本語

How to Fix Git “You have not concluded your merge” Error

​​Git​command line,Troubleshooting

If git merge or git pull shows You have not concluded your merge (MERGE_HEAD exists)., the previous merge is still unfinished. Either finish it with git commit (or git merge --continue), or cancel it with git merge --abort. After that, the same command will run normally.

This message appears when you run git pull on a shared team repository, get a merge conflict, fix the file and run git add, and then run git pull again without committing. I deliberately reproduced this error in a test environment and confirmed the message it shows and that it goes away after you fix the state.

Note

The test environment was Ubuntu 24.04, Git 2.43.0, and bash 5.2. I ran everything with LANG=C so the messages would be in English. For the remote, I used an empty repository created inside the same test environment, and I have replaced its path in the output with /path/to/origin. I did not test how Windows, macOS, Git GUI tools, or editor merge features display this.

Diagram of the merge in progress. When a conflict stops the merge and it is not yet resolved, merge or pull fails with an unmerged files error. After the file is fixed and staged with git add but not committed, You have not concluded your merge appears. Finish with git commit or git merge --continue, or cancel with git merge --abort, to get out of this state. (Labels in the image are in Japanese.)
Error shown after resolving a conflict and running add, but before committing

The error appears after you resolve and add

I merged the schedule branch into main, and index.html conflicted and stopped the merge.

console
$ git merge schedule
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.

I rewrote index.html and ran git add. Then git status showed All conflicts fixed but you are still merging. This means the conflict is resolved, but the merge is still in progress.

console
$ git add index.html

$ git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)

All conflicts fixed but you are still merging.
  (use "git commit" to conclude merge)

Changes to be committed:
	modified:   index.html

Here are the messages I got when I tried to merge another branch (footer) and when I ran git pull without committing. Both exited with code 128 and stopped without bringing anything in.

console
$ git merge footer
fatal: You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you merge.

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

From the second line on, the wording differs slightly between git merge and git pull. Both tell you to commit the previous merge before running the command again.

The same happens with a conflict caused by git pull. In my test environment, pull.rebase was not set. When both the local and remote branches had new commits, running git pull without --no-rebase stopped with fatal: Need to specify how to reconcile divergent branches. before any conflict. So I ran git pull with --no-rebase, which selects merge instead of rebase, and produced the conflict.

After I fixed the file and ran git add, running git pull again stopped with the same message as above.

console
$ git pull --no-rebase origin main
From /path/to/origin
 * branch            main       -> FETCH_HEAD
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.

$ git add index.html

$ git pull --no-rebase origin main
error: You have not concluded your merge (MERGE_HEAD exists).
hint: Please, commit your changes before merging.
fatal: Exiting because of unfinished merge.

MERGE_HEAD marks that a merge is in progress

The MERGE_HEAD exists part of the message means that a file named MERGE_HEAD exists in the .git directory. It contains the commit ID of the branch you were trying to merge (here, schedule).

console
$ ls .git/MERGE_HEAD
.git/MERGE_HEAD

$ cat .git/MERGE_HEAD
b97dfcf056ccffd465c0fe6bc057719e6d97cb45

$ git rev-parse schedule
b97dfcf056ccffd465c0fe6bc057719e6d97cb45

The official git merge reference states that when a merge stops because of a conflict, MERGE_HEAD points to the tip of the other branch. The git merge source (builtin/merge.c) and the git pull source (builtin/pull.c) both check for this file at the start and, if it exists, print this message and exit.

If you have not resolved the conflict yet, a different message appears

When I ran the same commands before running git add on the conflicted file, I got a different message, which reports the unresolved files before it reaches MERGE_HEAD.

console
$ git merge footer
error: Merging is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.

$ git pull origin main
error: Pulling is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.

In that case, first fix the conflicted file and run git add. How to resolve a conflicted file is covered in a separate article, "How to Resolve Git Merge Conflicts."

Fix 1: Commit to finish the merge

To finish the merge with your fixes, run git merge --continue. This creates the merge commit, and MERGE_HEAD is removed. In my test, I configured Git so it did not open an editor and committed with the default message Git prepared.

console
$ git merge --continue
[main 778bb29] Merge branch 'schedule'

$ ls .git/MERGE_HEAD
ls: cannot access '.git/MERGE_HEAD': No such file or directory

$ git status
On branch main
Your branch is ahead of 'origin/main' by 3 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

After this, when I ran the git merge footer and git pull origin main commands that had failed earlier, neither produced an error.

console
$ git merge footer
Merge made by the 'ort' strategy.
 footer.html | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 footer.html

$ git pull origin main
From /path/to/origin
 * branch            main       -> FETCH_HEAD
Already up to date.

Running git commit instead of git merge --continue has the same result. According to the official reference's explanation of how to resolve conflicts, git merge --continue checks that a merge is in progress and then runs git commit. When I had a conflict from git pull, finishing it with git commit --no-edit also let the same git pull succeed.

console
$ git commit --no-edit
[main 7232238] Merge branch 'main' of /path/to/origin

$ git pull --no-rebase origin main
From /path/to/origin
 * branch            main       -> FETCH_HEAD
Already up to date.

--no-edit is an option that commits with the message Git prepared, without opening an editor.

Warning

When I committed with a file path, as in git commit -m "message" index.html, it stopped with fatal: cannot do a partial commit during a merge. Do not specify file names when committing to finish a merge.

Fix 2: Cancel the merge and go back

If you have fixed the conflict but no longer want to merge, run git merge --abort. This removes MERGE_HEAD, and index.html returns to the content of main from before the merge, not to your fixed version.

console
$ git merge footer
fatal: You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you merge.

$ git merge --abort

$ ls .git/MERGE_HEAD
ls: cannot access '.git/MERGE_HEAD': No such file or directory

$ git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

$ cat index.html
<h1>ねこノート</h1>
<p>毎週土曜に更新します</p>

$ git log --oneline -1
677e9cb 更新日を土曜にする

$ git merge footer
Merge made by the 'ort' strategy.
 footer.html | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 footer.html

After the abort, the git merge footer that had failed earlier succeeded. According to the official reference for –abort, when MERGE_HEAD exists, git merge --abort works like git reset --merge. The reference also notes that if you had uncommitted changes before starting the merge, they may not be fully restored.

You cannot switch branches during a merge either

Trying to switch to another branch with git switch without finishing the merge also stops.

console
$ git switch footer
fatal: cannot switch branch while merging
Consider "git merge --quit" or "git worktree add".

The message suggests git merge --quit. According to the official reference, --quit only cancels the merge-in-progress state and leaves your working files and index as they are. To finish the merge, use git commit; to cancel it, use git merge --abort.

​Posted by 86