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

Summary

merge: CONFLICT (content): Merge conflict in <file> occurs when Git cannot automatically merge changes because two branches modified the same part of a file differently. To fix this, you must manually edit the conflicting files, decide which changes to keep, and complete the merge or rebase operation.

Context

When merging branches or pulling remote updates, Git attempts to automatically reconcile changes. However, when both sides edit the same lines, Git marks the conflict in the file and pauses the operation until you resolve it manually.

Probable Cause

  • Two branches modified identical sections of code differently.
  • Pulling remote changes that overlap with local commits.
  • Automatic merge failed to determine which version to prefer.
  • Rebase encountered conflicting edits across commits.

Quick Fix

  1. List conflicting files:
    git status
  2. Open the conflicted file(s): You’ll see conflict markers:
    <<<<<<< HEAD
    Your local version
    =======
    Incoming version from merge
    >>>>>>> branch-name
  3. Edit the file: Choose which changes to keep — local (HEAD), remote (incoming), or merge both manually.
  4. Remove all conflict markers: Delete every <<<<<<<, =======, and >>>>>>>.
  5. Mark as resolved:
    git add <file>
  6. Finalize the merge:
    git commit
    or if rebasing:
    git rebase --continue

Example

# Error during merge
$ git merge feature/login
Auto-merging src/app.js
CONFLICT (content): Merge conflict in src/app.js
Automatic merge failed; fix conflicts and then commit the result.

# Fix
$ git status
Unmerged paths:
  both modified: src/app.js

$ code src/app.js
# Edit file to resolve conflict manually

$ git add src/app.js
$ git commit -m "Resolved merge conflict in app.js"
[main 1a2b3c4] Resolved merge conflict in app.js

Alternate Scenarios

  • Modify/Delete conflict: One branch deleted the file, the other modified it. Choose whether to keep or remove the file.
  • Rebase conflict: Occurs while replaying commits. Fix and continue with:
    git rebase --continue
  • Abort the merge: If you want to cancel and restore the pre-merge state:
    git merge --abort

Pitfalls & Debug

  • Symptom → Merge aborted after conflicts. Fix → Resolve conflicts, stage files, and commit manually.
  • Symptom → Rebase interrupted mid-way. Fix → Use git rebase --continue after resolving all conflicts.
  • Symptom → Leftover conflict markers in files. Fix → Search for markers:
    git grep '<<<<<<< HEAD'

Verification & Next Steps

# Check if all conflicts resolved
git status

# Validate that no conflict markers remain
git grep '<<<<<<< HEAD'

# Confirm a clean merge graph
git log --graph --oneline

Best Practices

  • Pull frequently to minimize merge conflicts.
  • Use feature branches to isolate changes.
  • Leverage visual merge tools (VS Code, GitKraken, SourceTree) for side-by-side comparison.
  • Always review and test merged code before committing.

Sources

Git Documentation — git merge

Git Documentation — git rebase

Stack Overflow — How to resolve merge conflicts in Git

Labels

Tool/Git, OS/Cross-platform, Topic/Merge Conflicts