Skip to content

Resolving Conflicts

A conflict occurs when two branches modify the same line in the same file differently. Git doesn’t know which change to keep.

Think of it like two people editing the same sentence in a document:

  • You write: “The color is blue.”
  • Your colleague writes: “The color is red.”
  • Git asks: Which one is correct?
flowchart TB
Start[You pull latest main] --> Conflict[Merge conflict detected!]
Conflict --> Check["git status<br/>Shows conflicted files"]
Check --> Edit["Open the file<br/>Look for conflict markers"]
Edit --> Decide["Choose one side<br/>or write a new version"]
Decide --> Add["git add &lt;file&gt;<br/>Mark as resolved"]
Add --> Commit["git commit<br/>(no message needed)"]
Commit --> Done[✅ Conflict resolved!]
style Start fill:#3b82f6,color:#fff
style Conflict fill:#ef4444,color:#fff
style Done fill:#10b981,color:#fff

When a conflict happens, Git puts conflict markers in the file:

<<<<<<< HEAD
The color is blue.
=======
The color is red.
>>>>>>> feature-branch
MarkerMeaning
<<<<<<< HEADStart of your version (current branch)
=======Separator between the two versions
>>>>>>> feature-branchEnd of their version (incoming branch)

1. See which files have conflicts:

Terminal window
git status
# both modified: index.html

2. Open the conflicted file in your editor:

Terminal window
code index.html # VS Code

3. Find the conflict markers and fix them:

<<<<<<< HEAD
The color is blue.
=======
The color is red.
>>>>>>> feature-branch

4. Decide what to keep — one side, both, or something new:

The color is purple. ← You wrote a completely new version

5. Save the file, then mark it as resolved:

Terminal window
git add index.html
git commit # Git provides a default merge message

Terminal window
# 1. Setup
git init
echo "Hello" > file.txt
git add . && git commit -m "Initial"
# 2. Branch and commit
git checkout -b feature
echo "Feature content" > file.txt
git add . && git commit -m "Feature change"
# 3. Back to main, make a different change
git checkout main
echo "Main content" > file.txt
git add . && git commit -m "Main change"
# 4. Try to merge — conflict!
git merge feature
# Auto-merging file.txt
# CONFLICT: content in file.txt

The conflicted file.txt will look like:

<<<<<<< HEAD
Main content
=======
Feature content
>>>>>>> feature

Fix it, then git add file.txt and git commit.


  • Pull often — git pull before starting work
  • Communicate — let teammates know which files you’re editing
  • Small commits — easier to see what changed
  • Short-lived branches — merge or rebase frequently to stay in sync
  • Use VS Code — it has built-in conflict resolution UI (Accept Current / Accept Incoming / Accept Both)

  • Conflicts happen when two branches change the same line differently
  • Git marks conflicts with <<<<<<<, =======, and >>>>>>>
  • Fix: Open the file → edit the content → remove markers → save
  • Mark resolved: git add <file> → git commit
  • Conflicts are normal! Pull often and branch frequently to minimize them