By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
(Hyper-Practical, Zero-Fluff Study Guide)
A merge conflict happens when Git can’t automatically reconcile differences between two branches. Think of it like two chefs editing the same recipe—one adds garlic, the other removes it. Git doesn’t know which change to keep, so it pauses and asks you to decide.
Why this matters in production:- Broken deployments: If you merge conflicting code into main, your CI/CD pipeline might fail, or worse—deploy broken code to users.- Wasted time: Manually resolving conflicts in a large codebase (e.g., 50+ files) without a tool is error-prone and slow.- Team friction: Unresolved conflicts block other developers. If you’re the bottleneck, your team’s velocity drops.
main
Real-world scenario:You’re a DevOps engineer working on a microservice. Your teammate updates the API contract in feature/login, while you modify the same endpoints in feature/auth. When you try to merge into develop, Git throws a conflict. If you resolve it incorrectly, the service might crash in staging.
feature/login
feature/auth
develop
Superpower: A merge tool (like meld, kdiff3, or VS Code’s built-in resolver) lets you visually compare changes, pick which lines to keep, and resolve conflicts in minutes—not hours.
meld
kdiff3
? Merge Conflict Definition: Git’s way of saying, “I can’t decide which change to keep—you choose.” Production insight: Conflicts aren’t bugs; they’re a sign of parallel work. Ignoring them leads to broken builds.
? Three-Way Merge Definition: Git compares:
The incoming changes (the branch you’re merging). Production insight: Always check the ancestor to understand why the conflict exists.
? Conflict Markers (<<<<<<<, =======, >>>>>>>) Definition: Git inserts these in files to show conflicting sections. Example: ```python def calculate_discount(price): <<<<<<< HEAD return price * 0.9 # Your change: 10% discount ======= return price * 0.8 # Their change: 20% discount
<<<<<<<
=======
>>>>>>>
feature/login ``` Production insight: Never commit files with conflict markers—your code won’t run.
? Merge Tool Definition: A GUI app (e.g., meld, kdiff3, VS Code) that visualizes conflicts and lets you pick changes interactively. Production insight: CLI-only conflict resolution is slow and risky. A merge tool reduces errors by 80%.
VS Code
? .gitconfig Definition: Git’s config file where you set your default merge tool. Production insight: Configure this once to avoid typing git mergetool --tool=meld every time.
.gitconfig
git mergetool --tool=meld
? git mergetool Definition: The command that launches your configured merge tool. Production insight: Run this after Git reports a conflict (not before).
git mergetool
? git rerere (Reuse Recorded Resolution) Definition: Git remembers how you resolved a conflict and reapplies the fix if it sees the same conflict again. Production insight: Enable this in large projects to avoid re-resolving the same conflicts.
git rerere
? ours vs. theirs Definition:
ours
theirs
git checkout --ours file.txt
git checkout --theirs file.txt
git --version
# Clone a test repo (or use your own) git clone https://github.com/your-repo.git cd your-repo # Create two branches with conflicting changes git checkout -b feature/conflict-1 echo "Change from conflict-1" > conflict.txt git add conflict.txt git commit -m "Add conflict-1 change" git checkout -b feature/conflict-2 echo "Change from conflict-2" > conflict.txt git add conflict.txt git commit -m "Add conflict-2 change" # Try to merge (this will fail) git checkout feature/conflict-1 git merge feature/conflict-2
Expected output:
Auto-merging conflict.txt CONFLICT (content): Merge conflict in conflict.txt Automatic merge failed; fix conflicts and then commit the result.
Pick one of these tools and configure it:
# Install Meld (Linux: sudo apt install meld, macOS: brew install meld) git config --global merge.tool meld git config --global mergetool.meld.path "/usr/bin/meld" # Adjust path if needed git config --global mergetool.meld.trustExitCode true
# Install KDiff3 (Linux: sudo apt install kdiff3, macOS: brew install kdiff3) git config --global merge.tool kdiff3 git config --global mergetool.kdiff3.path "/usr/bin/kdiff3" # Adjust path git config --global mergetool.kdiff3.trustExitCode true
git config --global merge.tool vscode git config --global mergetool.vscode.cmd "code --wait $MERGED"
What happens:- Your merge tool opens with a 3-way diff (ancestor, yours, theirs).- You’ll see conflicting sections highlighted.- Use the GUI to: - Pick changes (click buttons or drag/drop). - Edit manually (if needed). - Save and exit when done.
Example (Meld): - Left pane: Your changes (ours).- Middle pane: Ancestor (common base).- Right pane: Their changes (theirs).- Bottom pane: Result (what will be saved).
bash cat conflict.txt # Should show your final merged content
bash git add conflict.txt
bash git commit -m "Merge branch 'feature/conflict-2' into feature/conflict-1"
git log --graph --oneline --all
* abc1234 Merge branch 'feature/conflict-2' into feature/conflict-1 |\ | * def5678 Add conflict-2 change * | 1234abc Add conflict-1 change |/ * 9876zyx Initial commit
master
bash git config --global rerere.enabled true
node_modules
.zip
[conflict: login-api]
bash grep -r "<<<<<<<" . && exit 1
git status
grep -r "<<<<<<<" .
--force
.gitignore
git rm -r --cached node_modules
api.js
Trap: git merge --abort is wrong—it cancels the merge entirely.
git merge --abort
Scenario: "After resolving a conflict, the file still shows <<<<<<<. What did you forget?"
git add <file>
Trap: git commit alone won’t work—you must git add first.
git commit
git add
Scenario: "Which merge tool is configured by default in Git?"
Trap: "vimdiff" is the default fallback, but it’s not a GUI tool.
Scenario: "How do you keep your changes and discard theirs for a single file?"
git merge --ours
Challenge:1. Create a Git repo with two branches (feature/a and feature/b).2. In both branches, modify the same line in README.md.3. Merge feature/b into feature/a and resolve the conflict using meld.4. Verify the merge with git log --graph.
feature/a
feature/b
README.md
git log --graph
Solution:
# 1. Create repo and branches mkdir merge-challenge && cd merge-challenge git init echo "Original line" > README.md git add README.md git commit -m "Initial commit" git checkout -b feature/a echo "Change from A" > README.md git add README.md git commit -m "Change from A" git checkout -b feature/b echo "Change from B" > README.md git add README.md git commit -m "Change from B" # 2. Merge and resolve git checkout feature/a git merge feature/b # Conflict! git mergetool # Use meld to pick "Change from A" or "Change from B" git add README.md git commit -m "Merge feature/b into feature/a" # 3. Verify git log --graph --oneline
Why it works:- git mergetool launches your configured GUI to resolve the conflict.- git add marks the file as resolved.- git log --graph shows the merge commit.
git merge <branch>
<branch>
git config --global merge.tool meld
git checkout --ours <file>
<file>
--ours
--theirs
git checkout --theirs <file>
git config --global rerere.enabled true
<<<<<<< HEAD
>>>>>>> <branch>
git config --global merge.tool
vscode
/usr/bin/meld
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.