How to fix warning: path 'file.txt' is unmerged in Git

GitBEGINNERLOWUpdated Dec 6, 2025ยท 201 views

This warning appears when you try to perform operations on a file that has unresolved merge conflicts. Git is telling you the file is in a conflicted state and requires manual resolution before you can checkout, add, or otherwise manipulate it normally.

Quick fix

Fixes warning: path 'file.txt' is unmerged

git status
  1. Check which files are unmerged
  2. View the conflicts in the file
  3. Resolve the conflicts manually
  4. Use git checkout to pick a version
git โ€” error
git status
warning: path 'file.txt' is unmerged

What this error means

The "warning: path 'file.txt' is unmerged" message indicates that Git has detected a merge conflict affecting the specified file. When Git encounters conflicting changes during a merge, rebase, or cherry-pick operation, it marks the affected files as "unmerged" until you manually resolve the conflicts. This warning commonly appears when you try to: - Run `git checkout` on a file with unresolved conflicts - Use `git add` on a file before resolving conflict markers - Attempt to switch branches while conflicts exist - Run `git stash` with uncommitted conflicts The file is in an intermediate state where Git has inserted conflict markers (<<<<<<<, =======, >>>>>>>) to show you the competing changes. Until you edit the file to resolve these conflicts and stage it, the file remains "unmerged" and many Git operations will be blocked or produce warnings. Understanding this warning is crucial because ignoring it and forcing operations can lead to lost work or a corrupted repository state. Git is protecting you from accidentally discarding important changes.

Typical symptoms

  • Running git checkout on a conflicted file shows 'warning: path is unmerged'
  • git status shows files under 'Unmerged paths' section
  • Attempting git add shows warning about unmerged files
  • Files contain conflict markers (<<<<<<, ======, >>>>>>) that weren't resolved
  • git stash fails with 'needs merge' error
  • Cannot switch branches due to unmerged paths
  • git diff shows 'diff --cc' output indicating merge conflicts

Common causes

  1. A merge operation was started but conflicts weren't fully resolved
  2. A rebase operation encountered conflicts that weren't addressed
  3. A cherry-pick introduced conflicting changes
  4. Conflict markers were partially removed but file wasn't staged
  5. The terminal or editor was closed during conflict resolution
  6. Running git checkout to try to 'fix' a conflicted file (which doesn't resolve it)
  7. A pull operation brought in changes conflicting with local modifications

How to fix "warning: path 'file.txt' is unmerged"

1Check which files are unmerged

First, identify all files in the unmerged state:

bash
git status

Example output showing unmerged files:

bash
On branch main
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   file.txt
	both modified:   src/config.js

You can also list only unmerged files:

bash
git diff --name-only --diff-filter=U

This shows you exactly which files need attention before you can proceed.

2View the conflicts in the file

Open the conflicted file and look for conflict markers:

bash
# View the file content
cat file.txt

# Or use git diff to see the conflicts
git diff file.txt

Conflict markers look like this:

bash
<<<<<<< HEAD
This is your current version of the line
=======
This is the incoming version from the other branch
>>>>>>> feature-branch

The section between <<<<<<< HEAD and ======= is your current branch's content.
The section between ======= and >>>>>>> is the incoming content from the merge.

You need to decide which version to keep, or combine them manually.

3Resolve the conflicts manually

Edit the file to resolve the conflict:

1. Open the file in your editor (VS Code, vim, nano, etc.)
2. Find the conflict markers (<<<<<<<, =======, >>>>>>>)
3. Choose what to keep:
- Keep your version (HEAD)
- Keep the incoming version
- Combine both versions
- Write something completely new
4. Remove all conflict markers
5. Save the file

Example resolution - keeping the incoming change:

Before:

bash
<<<<<<< HEAD
const timeout = 3000;
=======
const timeout = 5000;
>>>>>>> feature-branch

After (resolved):

bash
const timeout = 5000;

Using VS Code:
VS Code highlights conflicts and offers buttons:
- "Accept Current Change" - keeps HEAD version
- "Accept Incoming Change" - keeps the other branch
- "Accept Both Changes" - includes both versions
- "Compare Changes" - opens side-by-side view

4Use git checkout to pick a version

If you want to completely accept one version without editing:

Accept your current version (HEAD):

bash
git checkout --ours file.txt

Accept the incoming version:

bash
git checkout --theirs file.txt

Important: After using --ours or --theirs, you still need to stage the file:

bash
git add file.txt

For all conflicted files at once:

bash
# Accept all of yours
git checkout --ours .
git add .

# Or accept all of theirs
git checkout --theirs .
git add .

Use this approach when you're certain one version is completely correct.

5Stage the resolved file

After resolving conflicts, mark the file as resolved by staging it:

bash
git add file.txt

Or stage all resolved files:

bash
git add .

Verify the file is no longer unmerged:

bash
git status

You should see the file move from "Unmerged paths" to "Changes to be committed":

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

Changes to be committed:
	modified:   file.txt

The warning about "path is unmerged" will no longer appear for this file.

6Complete the merge or rebase

Once all conflicts are resolved and staged, finish the operation:

For a merge:

bash
git commit

Git will open your editor with a merge commit message. Save and close to complete.

For a rebase:

bash
git rebase --continue

Git will continue applying the remaining commits.

For a cherry-pick:

bash
git cherry-pick --continue

Verify completion:

bash
git status

You should see a clean working directory:

bash
On branch main
nothing to commit, working tree clean
7Abort the operation if needed

If you want to abandon the merge/rebase entirely and go back to the previous state:

Abort a merge:

bash
git merge --abort

Abort a rebase:

bash
git rebase --abort

Abort a cherry-pick:

bash
git cherry-pick --abort

This restores your repository to the state before the operation started. All conflict resolution work will be discarded.

When to abort:
- You realize the merge/rebase was a mistake
- The conflicts are too complex to resolve right now
- You need to consult with teammates about the correct resolution
- You want to try a different approach (like merging in smaller pieces)

8Reset conflict markers to try again

If you made a mistake while resolving and want to start over on a file:

bash
# Restore the conflict markers
git checkout --conflict=merge file.txt

Or using git restore (Git 2.23+):

bash
git restore --conflict=merge file.txt

This puts the conflict markers back so you can try resolving again.

To unstage a file without losing your resolution:

bash
git restore --staged file.txt

To see the original versions during conflict:

bash
# See your version (stage 2)
git show :2:file.txt

# See their version (stage 3)
git show :3:file.txt

# See the common ancestor (stage 1)
git show :1:file.txt

This helps you understand what each side changed before deciding how to merge.

Advanced notes

Understanding merge stages

During a conflict, Git stores three versions of each conflicted file in the index:
- Stage 1: The common ancestor (base version)
- Stage 2: Your version (HEAD/ours)
- Stage 3: Their version (incoming/theirs)

You can view these with:

bash
git ls-files -u

Output shows the stages:

bash
100644 abc123 1 file.txt  # ancestor
100644 def456 2 file.txt  # ours (HEAD)
100644 789abc 3 file.txt  # theirs

Using git mergetool

For complex conflicts, a visual merge tool can help:

bash
git mergetool

Configure your preferred tool:

bash
# Use VS Code
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait $MERGED'

# Use vimdiff
git config --global merge.tool vimdiff

# Use meld (Linux)
git config --global merge.tool meld

Rerere: Remember conflict resolutions

Enable rerere to have Git remember how you resolved specific conflicts:

bash
git config --global rerere.enabled true

Next time you encounter the same conflict, Git can auto-resolve it.

Diff3 conflict style

Get more context in conflict markers by enabling diff3 style:

bash
git config --global merge.conflictstyle diff3

This shows the common ancestor between the two versions:

bash
<<<<<<< HEAD
your version
||||||| merged common ancestors
original version
=======
their version
>>>>>>> branch

Checking for whitespace conflicts

Sometimes conflicts are caused by whitespace differences:

bash
# Ignore whitespace during merge
git merge -Xignore-space-change branch-name

# Ignore all whitespace
git merge -Xignore-all-space branch-name

Prevention strategies

- Pull/merge frequently to catch conflicts early
- Communicate with team about who's modifying which files
- Use smaller, focused branches that merge quickly
- Consider using trunk-based development for reduced conflicts

Frequently asked questions

What does "warning: path 'file.txt' is unmerged" mean?
txt' is unmerged" message indicates that Git has detected a merge conflict affecting the specified file. When Git encounters conflicting changes during a merge, rebase, or cherry-pick operation, it marks the affected files as "unmerged" until you manually resolve the conflicts. This warning commonly appears when you try to: - Run git checkout on a file with unresolved conflicts - Use git add on a file before resolving conflict markers - Attempt to switch branches while conflicts exist - Run git stash with uncommitted conflicts The file is in an intermediate state where Git has inserted conflict markers (<<<<<<<, =======, >>>>>>>) to show you the competing changes.
How do I fix "warning: path 'file.txt' is unmerged"?
This warning appears when you try to perform operations on a file that has unresolved merge conflicts. Git is telling you the file is in a conflicted state and requires manual resolution before you can checkout, add, or otherwise manipulate it normally.
What causes "warning: path 'file.txt' is unmerged"?
A merge operation was started but conflicts weren't fully resolved A rebase operation encountered conflicts that weren't addressed A cherry-pick introduced conflicting changes
Is the "warning: path 'file.txt' is unmerged" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading