Read Anthropic’s case study about Graphite Reviewer

How to resolve the Git error "error merging is not possible because you have unmerged files"

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


When using Git, you may encounter the error message: error: merging is not possible because you have unmerged files. This error occurs when you attempt to merge branches that have unresolved conflicts from previous merge attempts. This guide provides a detailed explanation of why this error occurs and how to resolve it effectively.

The error error: merging is not possible because you have unmerged files indicates that there are conflicting changes between branches that need to be resolved before you can proceed with the merge. Git halts the merge process to prevent conflicting changes from being inadvertently committed to the repository.

First, you need to identify the files that have conflicts. You can use the git status command to list these files:

Terminal
git status

This command will show you a list of unmerged paths and the files that need your attention.

To resolve conflicts, you need to open each conflicting file and manually edit the sections where Git has identified conflicts. Git marks the conflicted areas with <<<<<<<, =======, and >>>>>>> lines. Here’s an example of what a conflict might look like:

Terminal
<<<<<<< HEAD
Current changes in your branch
=======
Incoming changes from the branch you are merging
>>>>>>> branch-name

You need to decide which changes to keep, edit the file accordingly, and remove the conflict markers (<<<<<<<, =======, and >>>>>>>).

After manually resolving the conflicts in a file, you need to mark the file as resolved using git add:

Terminal
git add <file_path>

Replace <file_path> with the path to the file you resolved. Repeat this step for each conflicted file.

Once all conflicts are resolved and marked, you need to commit the changes. This can be done with the following commands:

Terminal
git commit

Git will prompt you to enter a commit message. You can provide a message that indicates the resolution of merge conflicts, such as "Resolved merge conflicts".

After committing the resolved changes, you can proceed with the merge:

Terminal
git merge <branch_name>

Replace <branch_name> with the name of the branch you were attempting to merge.

Let’s walk through a complete example to illustrate these steps.

  1. You try to merge a branch called feature-branch into main:

    Terminal
    git checkout main
    git merge feature-branch
  2. Git reports an error due to unmerged files. You check the status:

    Terminal
    git status

    The output shows:

    Terminal
    On branch main
    You have unmerged paths.
    (fix conflicts and run "git commit")
    Unmerged paths:
    (use "git add <file>..." to mark resolution)
    both modified: file1.txt
    both modified: file2.txt
  3. Open file1.txt and file2.txt, manually resolve conflicts, and remove conflict markers. For more detailed instructions, see this guide on resolving Git merge conflicts.

  4. Mark the files as resolved:

    Terminal
    git add file1.txt
    git add file2.txt
  5. Commit the resolved changes:

    Terminal
    git commit -m "Resolved merge conflicts in file1.txt and file2.txt"
  6. Complete the merge:

    Terminal
    git merge feature-branch

If after following these steps you are still unable to resolve the Git error error: merging is not possible because you have unmerged files, see the official Git documentation.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2