[git] Git merge error "commit is not possible because you have unmerged files"

I forgot to git pull my code before editing it; when I committed the new code and tried to push, I got the error "push is not possible".

At that point I did a git pull which made some files with conflict highlighted. I removed the conflicts but I don't know what to do from here.

I tried to git commit again but it says the "commit is not possible because you have unmerged files":

error: Committing is not possible because you have unmerged files.

This question is related to git git-merge

The answer is


So from the error above. All you have to do to fix this issue is to revert your code. (git revert HEAD) then git pull and then redo your changes, then git pull again and was able to commit or merge with no errors.


This error occurs when you resolve the conflicts but the file still needs to be added in the stage area. git add . would solve it. Then, try to commit and merge.


I've had a similar issue which boiled down to removing files under "unmerged paths"

Those files had to be removed using git rm


You need to do two things. First add the changes with

git add .
git stash  

git checkout <some branch>

It should solve your issue as it solved to me.


Since git 2.23 (August 2019) you now have a shortcut to do that: git restore --staged [filepath]. With this command, you could ignore a conflicted file without needing to add and remove that.

Example:

> git status

  ...
  Unmerged paths:
    (use "git add <file>..." to mark resolution)
      both modified:   file.ex

> git restore --staged file.ex

> git status

  ...
  Changes not staged for commit:
    (use "git add <file>..." to update what will be committed)
    (use "git restore <file>..." to discard changes in working directory)
      modified:   file.ex


You can use git stash to save the current repository before doing the commit you want to make (after merging the changes from the upstream repo with git stash pop). I had to do this yesterday when I had the same problem.