What is it?
A merge conflict occurs when two branches changed the same part of the same file. Git cannot automatically reconcile them — you must manually choose which version to keep.
Why does it matter?
Merge conflicts are inevitable in team development. Understanding conflict markers and resolving them confidently is a critical professional skill.
Learn how to resolve merge conflicts — conflict markers, merge tools, and prevention.
Real-World Use Cases
- 👥 Team development - Two developers edited the same function — resolve whose logic wins or combine both.
- 🔄 Branch sync - Regular rebasing from main prevents painful large conflicts.
- 🌐 Open source - Upstream changed files your fork also changed — resolve in your PR.
- ⚡ Hotfix merging - A hotfix conflicts with a feature branch that touched the same file.
Conflict Markers
# In conflicted file Git marks:
# <<<<<<< HEAD (your branch changes)
# your code here
# ======= (separator)
# their code here
# >>>>>>> feature/auth (incoming branch)
#
# RESOLVE: choose, combine, or rewrite
# Then: git add file.php && git commit
Resolving Conflicts
git status # see conflicted files
git mergetool # open visual merge tool
# After resolving in editor:
git add login.php
git commit -m "Merge: keep email normalisation from feature/auth"
# Accept one entire side
git checkout --ours file.json # keep your version
git checkout --theirs file.json # take their version
Prevention
# 1. Rebase from main frequently
git fetch origin && git rebase origin/main
# 2. See conflicts before they happen
git merge --no-commit --no-ff feature/auth
git diff --cached
git merge --abort # if you need more time
# 3. Keep branches short-lived (< 1 week)
Q: How do I prevent merge conflicts?
Frequent integration: merge or rebase from main at least daily. Keep branches short-lived (under a week). Communicate which files you are editing. Organise code into small focused files so two people are rarely in the same file.
Comments (0)
No comments yet. Be the first!
Leave a Comment