How to fix warning: path 'file.txt' is unmerged in Git
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- Check which files are unmerged
- View the conflicts in the file
- Resolve the conflicts manually
- Use git checkout to pick a version
git statuswarning: 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
- 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
- Conflict markers were partially removed but file wasn't staged
- The terminal or editor was closed during conflict resolution
- Running git checkout to try to 'fix' a conflicted file (which doesn't resolve it)
- A pull operation brought in changes conflicting with local modifications
How to fix "warning: path 'file.txt' is unmerged"
First, identify all files in the unmerged state:
git statusExample output showing unmerged files:
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.jsYou can also list only unmerged files:
git diff --name-only --diff-filter=UThis shows you exactly which files need attention before you can proceed.
Open the conflicted file and look for conflict markers:
# View the file content
cat file.txt
# Or use git diff to see the conflicts
git diff file.txtConflict markers look like this:
<<<<<<< HEAD
This is your current version of the line
=======
This is the incoming version from the other branch
>>>>>>> feature-branchThe 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.
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:
<<<<<<< HEAD
const timeout = 3000;
=======
const timeout = 5000;
>>>>>>> feature-branchAfter (resolved):
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
If you want to completely accept one version without editing:
Accept your current version (HEAD):
git checkout --ours file.txtAccept the incoming version:
git checkout --theirs file.txtImportant: After using --ours or --theirs, you still need to stage the file:
git add file.txtFor all conflicted files at once:
# 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.
After resolving conflicts, mark the file as resolved by staging it:
git add file.txtOr stage all resolved files:
git add .Verify the file is no longer unmerged:
git statusYou should see the file move from "Unmerged paths" to "Changes to be committed":
On branch main
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)
Changes to be committed:
modified: file.txtThe warning about "path is unmerged" will no longer appear for this file.
Once all conflicts are resolved and staged, finish the operation:
For a merge:
git commitGit will open your editor with a merge commit message. Save and close to complete.
For a rebase:
git rebase --continueGit will continue applying the remaining commits.
For a cherry-pick:
git cherry-pick --continueVerify completion:
git statusYou should see a clean working directory:
On branch main
nothing to commit, working tree cleanIf you want to abandon the merge/rebase entirely and go back to the previous state:
Abort a merge:
git merge --abortAbort a rebase:
git rebase --abortAbort a cherry-pick:
git cherry-pick --abortThis 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)
If you made a mistake while resolving and want to start over on a file:
# Restore the conflict markers
git checkout --conflict=merge file.txtOr using git restore (Git 2.23+):
git restore --conflict=merge file.txtThis puts the conflict markers back so you can try resolving again.
To unstage a file without losing your resolution:
git restore --staged file.txtTo see the original versions during conflict:
# 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.txtThis 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:
git ls-files -uOutput shows the stages:
100644 abc123 1 file.txt # ancestor
100644 def456 2 file.txt # ours (HEAD)
100644 789abc 3 file.txt # theirsUsing git mergetool
For complex conflicts, a visual merge tool can help:
git mergetoolConfigure your preferred tool:
# 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 meldRerere: Remember conflict resolutions
Enable rerere to have Git remember how you resolved specific conflicts:
git config --global rerere.enabled trueNext time you encounter the same conflict, Git can auto-resolve it.
Diff3 conflict style
Get more context in conflict markers by enabling diff3 style:
git config --global merge.conflictstyle diff3This shows the common ancestor between the two versions:
<<<<<<< HEAD
your version
||||||| merged common ancestors
original version
=======
their version
>>>>>>> branchChecking for whitespace conflicts
Sometimes conflicts are caused by whitespace differences:
# Ignore whitespace during merge
git merge -Xignore-space-change branch-name
# Ignore all whitespace
git merge -Xignore-all-space branch-namePrevention 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
- ๐Git Official Documentation
- ๐How to Resolve Conflicts - Git Documentation(Official Docs)
- ๐Basic Merge Conflicts - Git Pro Book(Official Docs)
- ๐
- ๐Git Merge Conflicts - Atlassian Git Tutorial(Official Docs)
- ๐ฌError: Path 'xxx' is unmerged - Stack Overflow(Stack Overflow)