[Git] Error: merge: CONFLICT (content) — Merge conflict in — How to Fix It

Summary

The Git message merge: CONFLICT (content): Merge conflict in <file> means that two branches have edited the same section of a file differently, and Git can’t decide which version to keep automatically. To resolve it, you must manually edit the conflicting files, remove conflict markers, decide which changes to keep, and then stage and commit the resolution.

Context

Merge conflicts are a normal part of collaborative development when multiple contributors modify overlapping sections of code or text. Git performs automatic merges whenever possible, but when it detects incompatible edits in the same region, it stops and asks for human intervention. During a merge or rebase, Git inserts special conflict markers (<<<<<<<, =======, >>>>>>>) to show the differences between your branch (HEAD) and the incoming branch. The developer must choose which code to keep or combine. Conflicts can occur on any platform or editor, including Linux, macOS, Windows, Git Bash, and IDEs like VS Code.

Probable Cause

  • Two branches modified the same lines in a file differently.
  • Parallel edits made to overlapping code or documentation sections.
  • Automatic merge algorithms unable to reconcile diverging content.
  • Pulling remote updates that overlap with local unpushed commits.

Quick Fix

Follow these steps to locate, edit, and finalize the merge resolution:

  1. List conflicting files:
git status
  1. Open each file marked under “Unmerged paths”. You’ll see conflict markers like:
<<<<<<< HEAD
Your local version
=======
Incoming version from merged branch
>>>>>>> branch-name
  1. Decide which lines to keep — local (HEAD), incoming (branch), or a combination of both.
  2. Remove all conflict markers (<<<<<<<, =======, >>>>>>>) once resolved.
  3. Stage the resolved file:
git add <file>
  1. When all conflicts are resolved, finalize the merge:
git commit
  1. If you were rebasing, continue with:
git rebase --continue

Full Example

A developer merges feature into main and gets:

merge: CONFLICT (content): Merge conflict in src/app.js
Automatic merge failed; fix conflicts and then commit the result.

Inspecting the file shows:

<<<<<<< HEAD
console.log("Hello from main");
=======
console.log("Hello from feature");
>>>>>>> feature

To resolve, the developer decides to combine both lines:

console.log("Hello from main and feature");

They save, stage, and commit:

git add src/app.js
git commit -m "Resolve merge conflict in app.js"

The merge completes successfully, and both sets of changes are now integrated.

Pitfalls & Debug

  • Symptom: Conflict markers remain after commit → Fix: Search with git grep '<<<<<<< HEAD' and clean any leftover markers.
  • Symptom: Merge aborted accidentally → Fix: Run git merge --abort and start again cleanly.
  • Symptom: Rebase stuck after conflict → Fix: Resolve all files, then run git rebase --continue.
  • Symptom: Unsure which branch changes are yours → Fix: Lines above ======= are from your branch (HEAD).
  • Symptom: Complex multi-file conflicts → Fix: Use a visual merge tool like VS Code, GitKraken, or SourceTree.

Validation & Next Steps

After committing, confirm a clean merge:

git log --graph --oneline

Ensure no conflict markers remain:

git grep '<<<<<<< HEAD'

Optionally, check for leftover formatting or whitespace issues:

git diff --check

Once verified, push the resolved branch to synchronize it with the remote repository.

Sources

Git documentation — git-merge
Pro Git Book — Conflict resolution section
Stack Overflow — “merge: CONFLICT (content)” resolution discussions
Atlassian Git tutorials — Visual merge tools and examples

Labels: Tool/Git, OS/Windows-macOS-Linux, Topic/Merge-Conflict-Resolution