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.
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.
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.
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
warning: BOM detected in file, this may cause issues
UTF-8 Byte Order Mark (BOM) detected in file
fatal: Server does not support --shallow-exclude
Server does not support --shallow-exclude
warning: filtering out blobs larger than limit
Git partial clone filtering large blobs warning
fatal: Server does not support --shallow-since
Server does not support --shallow-since in Git
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server