A merge conflict occurs when both branches have changed the same part of a file. Git marks the conflicting section with special markers. You must manually edit the file to resolve the conflict, then stage the resolved file and complete the merge.
Git
Beginner
11 min read
Resolving Merge Conflicts
Example
# Start a merge that causes a conflict:
git switch main
git merge feature/header-redesign
# CONFLICT (content): Merge conflict in src/Header.js
# Git marks the conflict in the file:
# <<<<<<< HEAD
# <h1>My App</h1>
# =======
# <h1>My Awesome Application</h1>
# >>>>>>> feature/header-redesign
# Resolve the conflict:
# 1. Open the file in your editor
# 2. Choose which version to keep (or write a combination)
# 3. Delete ALL conflict markers: <<<<<<<, =======, >>>>>>>
# After editing the file:
# <h1>My Awesome Application</h1>
# Mark the conflict as resolved:
git add src/Header.js
# Complete the merge:
git commit
# Git pre-fills: "Merge branch 'feature/header-redesign'"
# See files with conflicts:
git diff --name-only --diff-filter=U
# Use a visual merge tool:
git mergetool
# To abort the merge and start over:
git merge --abort