Fix Git Error: fatal: cannot do a partial commit during a merge

beginner📦 Git2026-06-06| Any OS (Linux, Windows, macOS) using Git via CLI or GUI clients like VS Code or GitKraken.

Error Message

fatal: cannot do a partial commit during a merge.
#git#merge#commit#conflict#partial-commit

The Error Message

You are in the middle of a merge, you have hand-polished your code, and you try to commit just one specific file. Instead of a success message, Git hits you with this roadblock:

$ git commit -m "Fix login logic" src/auth.py
fatal: cannot do a partial commit during a merge.

Why Git is Blocking You

Git plays by strict rules during a merge. When you start a merge (via git merge or git pull), Git enters a temporary state where it expects a single, "atomic" outcome. It wants you to resolve all conflicts and then record the entire result as one merge commit.

Unlike a standard commit, a merge commit has two parents. It represents the union of two different histories. Because of this, Git refuses to let you commit only part of that union. If you try to commit auth.py while index.html is still sitting there with conflict markers, you would create a "half-merged" state that could lead to a corrupted history later.

Three Ways to Fix It

You have three paths forward depending on whether you want to finish the merge, bypass the restriction, or just start over.

Solution 1: The Reliable Way (Commit Everything)

This is the standard procedure. Once you have resolved your conflicts, you must tell Git that the entire project is ready. Do not name specific files in your commit command.

  • Stage every resolved file (e.g., your main.py or styles.css):

git add .

  
  - Verify your status:
    ```
git status

You should see: "All conflicts fixed but you are still merging."

  • Finalize the merge without specifying filenames:

git commit -m "Merge feature-login into main"

  

### Solution 2: The "Include" Shortcut (-i)
If you are a power user and only want to commit the files you have already staged, you can use the `-i` (include) flag. This tells Git to stage the file you named and then commit everything that is currently ready.

git commit -i src/auth.py -m "Partial fix during merge"


**Warning:** Use this sparingly. It doesn't actually finish the merge process if other files are still pending or broken. It is a quick fix, not a permanent solution for complex merges.

### Solution 3: The Escape Hatch (Abort)
Sometimes things go sideways. If the merge is too messy or you realized you should have committed your local changes 5 minutes ago, just cancel the whole thing.

  - Kill the merge process:
    ```
git merge --abort
  • Your files will snap back to the state they were in before the merge started. Now you can commit your specific file normally:

git commit src/auth.py -m "Save my work before merging"

  
  - Try the merge again:
    ```
git merge feature-branch

How to Verify the Fix

Once you’ve applied one of these fixes, run a quick health check:

git status

If successful, you will see nothing to commit, working tree clean. If you are still in a merge, you will see the dreaded "You have unmerged paths" warning.

To see the result in your history, check the last 3 entries:

git log --oneline -n 3

Pro Tips to Stay Out of Trouble

  • Clean your house first: Never start a merge with uncommitted changes. Run git status before git pull to ensure your working directory is spotless.
  • Drop the filenames: When finishing a merge, get into the habit of typing git commit (with no arguments). Git will automatically open your editor with a pre-filled merge message, saving you from typos.
  • Stage as you go: As you fix conflicts in different files, use git add [filename] immediately so you don't lose track of your progress.

Related Error Notes