Data report"State of code review 2024" is now liveRead the full report

How to resolve the git error "fatal cannot do a partial commit during a merge"

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

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


When you encounter the git error message "fatal: cannot do a partial commit during a merge," it typically means that Git is preventing you from making a commit because all conflicts resulting from a merge must be resolved first. This guide will walk you through understanding and resolving this error, ensuring a smooth merge process in your Git workflow.

The error "fatal: cannot do a partial commit during a merge" occurs during a merge operation in Git when trying to commit only a subset of changes. Git requires that all merge conflicts be fully resolved and added to the staging area before a commit can be completed. This is because a merge commit should represent a fully resolved state of the merging branches.

You may see this during a conflicted merge. This happens when you've initiated a merge that resulted in conflicts. Instead of adding all resolved files to the staging area, you attempt to commit only some of them.

Step 1: Check for unresolved conflicts

First, identify if there are any unresolved conflicts in your repository:

Terminal
git status

This command will list files that have conflicts. Files marked as "unmerged" need your attention.

Step 2: Resolve the conflicts

Open each conflicted file and make the necessary changes to resolve the conflicts. Conflicts are typically marked within the file by conflict markers (<<<<<<<, =======, >>>>>>>). Remove these markers after resolving the differences.

For a more detailed walkthrough see this guide on resolving merge conflicts in Git.

Step 3: Add the resolved files to the staging area

Once you resolve all conflicts in a file, add it to the staging area:

Terminal
git add <file_path>

Repeat this for all resolved files. It's crucial to add all files that were part of the conflict resolution, not just a subset.

Step 4: Verify all conflicts are resolved

Before committing, ensure all conflicts are resolved and added:

Terminal
git status

If all files are staged (and no files are listed as unmerged), you're ready to proceed.

Step 5: Commit the merge

Now, complete the merge commit by committing the changes:

Terminal
git commit

This will open an editor to enter a commit message for the merge. Save and close the editor to finalize the commit.

  • Consistency in conflict resolution: Ensure that all team members resolve conflicts in a consistent manner to avoid reintroducing errors during merges.
  • Regularly pulling changes: Frequently pulling changes from the remote repository can help reduce the complexity and number of conflicts during merges.

For further reading see the official Git documentation.

Git gud
"It's the first Git workflow I've used that actually feels good."
–@robboclancy
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