Git Conflicts in VS Code: A Beginner-Friendly Guide
Learn how to handle Git conflicts in VS Code with confidence - perfect for junior developers.

Prerequisites #
Before diving in, make sure you have:
• VS Code installed
• Git installed and configured
• Basic understanding of Git commands (commit, push, pull)
Quick Start Guide #
Got a conflict right now? Here's what to do:
- Don't panic! Conflicts are normal
- Open VS Code
- Look for files marked with "C" or "!" in the Source Control panel
- Right-click the file → "Resolve in Merge Editor"
- Follow the visual guides to resolve the conflict
- Open Source Control:
- Open the Merge Editor:
- Your flavor (left panel)
- The mixed flavor (middle panel)
- Their flavor (right panel)
- Accept Yours (
Ctrl+1
or⌘1
): - Accept Theirs (
Ctrl+2
or⌘2
): - Combine Both (
Ctrl+3
or⌘3
): - Try the "Compare Changes" feature (
Ctrl+4
or⌘4
) - Ask a teammate to review
- Use
git merge --abort
to start over - Using VS Code UI:
- Using Quick Open:
<strong>Branch Comparison</strong>:
- Click GitLens icon
- Select "Search & Compare"
- Choose branches to compare
- See all differences visually
- Use GitLens when:
- Use Git Graph when:
- Use Git History when:
- Use Merge Conflict Jump when:
- Create a branch and make changes
- Have a friend make different changes
- Practice merging and resolving conflicts
- Repeat with different types of files
Now, let's learn the details...
Understanding Git Conflicts (The Basics) What's a Conflict?Imagine you and your friend are editing the same document:
• You change a line to say "Hello World"
• Your friend changes the same line to say "Hi there"
• Git doesn't know which version to keep
That's a conflict! Git needs your help to decide what to keep.
When Do Conflicts Happen?Conflicts typically occur when:
Your Branch: A → B → C → D /
Main Branch: A → E → F → G
Both branches changed the same code differently, and now Git needs help merging them.
VS Code's Conflict Tools (Your New Best Friends) 1. Visual IndicatorsVS Code helps you spot conflicts easily:
• 🔴 Red marks in the file explorer
• ❗ Exclamation marks in source control
• 🔄 Conflict markers in the file
2. Conflict Markers Explained
<<<<<<< HEAD (Your Changes) console.log("Hello World"); ======= console.log("Hi there");
>>>>>>> branch-name (Their Changes)
Think of it like this:
• Everything between <<<<<<< HEAD
and =======
is YOUR code
• Everything between =======
and >>>>>>>
is THEIR code
When you get a conflict message, here's what to do:
• Click the branching icon in VS Code's sidebar
• Or press Ctrl+Shift+G
(Windows/Linux) or ⌘+Shift+G
(Mac)
• Look for files with "C" or "!" badge
Choose any of these methods:
• Right-click → "Resolve in Merge Editor"
• Click "Resolve in Merge Editor" button
• Use Command Palette (Ctrl+Shift+P
or ⌘+Shift+P
) → type "merge editor"
┌─────────────┬─────────────┬─────────────┐ │ YOUR │ FINAL │ THEIR │ │ CHANGES │ RESULT │ CHANGES │ │ (1) │ (2) │ (3) │
└─────────────┴─────────────┴─────────────┘
Think of it like choosing between ice cream flavors:
You have three main options:
• Like saying "My changes are correct"
• Click "+" above your changes
• Like saying "Their changes are correct"
• Click "+" above their changes
• Like mixing both ice cream flavors
• Edit the middle panel directly
Real-World Examples #
1. Simple Text Conflict
// The conflict <<<<<<< HEAD const greeting = "Hello"; ======= const greeting = "Hi"; >>>>>>> feature/greetings // How to think about it: // 1. Do we want "Hello"? (yours) // 2. Do we want "Hi"? (theirs)
// 3. Or maybe something else? (combine)
// The conflict function Button() { <<<<<<< HEAD return <button className="blue">Click me</button>; ======= return <button className="red">Press here</button>; >>>>>>> feature/styling } // Think about: // 1. Which style do we want? (blue or red) // 2. Which text is better? ("Click me" or "Press here")
// 3. Maybe combine them?
Common Mistakes to Avoid #
❌ Mistake 1: Panic-Closing VS Code What happens: You see conflicts and close VS Code hoping they'll disappear Instead: Stay calm, conflicts are normal and fixable ❌ Mistake 2: Accepting All Changes Blindly What happens: You click "Accept All Incoming" without checking Instead: Review each change carefully ❌ Mistake 3: Forgetting to Test What happens: You resolve conflicts but don't test if the code works Instead: Always test after resolving conflictsBest Practices (Your Conflict Checklist) #
Before Resolution:• [ ] Take a deep breath
• [ ] Understand what each branch was trying to do
• [ ] Talk to your team if needed
During Resolution:• [ ] Open each conflicted file in the Merge Editor
• [ ] Review changes carefully
• [ ] Think about what the code should actually do
• [ ] Make thoughtful decisions
After Resolution:• [ ] Test the code
• [ ] Run your test suite
• [ ] Commit the changes
• [ ] Push your code
Preventing Conflicts 1. Pull Changes Often
# Start your day with:
git pull origin main
• Tell them which files you're working on
• Ask about ongoing changes
• Use feature flags for big changes
3. Keep Branches Short-Lived• Create small, focused branches
• Merge frequently
• Keep up to date with main
Need Help? If You Get Stuck:
# Safety commands if you need them: git merge --abort # Stop the merge
git reset --hard HEAD # Reset to last commit
• Extension ID: eamodio.gitlens
• Why it helps with conflicts:
• Shows who changed each line (blame annotations)
• Compare branches visually
• See commit history inline
• Helps understand why conflicts occurred
2. Git History• Extension ID: donjayamanne.githistory
• Why it helps with conflicts:
• Visual file and line history
• Compare branches easily
• See what changed between commits
• Understand how conflicts happened
3. Git Graph• Extension ID: mhutchie.git-graph
• Why it helps with conflicts:
• Visual representation of your Git history
• See where branches diverged
• Understand merge history
• Spot potential conflict areas before they happen
4. Merge Conflict Jump• Extension ID: marvhen.rebase-editor
• Why it helps with conflicts:
• Jump between conflicts easily
• Keyboard shortcuts for navigation
• Shows number of remaining conflicts
• Perfect for files with multiple conflicts
How to Install These Extensions: • Click Extensions icon in sidebar (or press Ctrl+Shift+X
/ ⌘+Shift+X
)
• Search for extension name
• Click "Install"
ext install eamodio.gitlens
ext install donjayamanne.githistory
ext install mhutchie.git-graph
ext install marvhen.rebase-editor
<strong class="text-lg">Extension Tips for Conflict Resolution</strong>
<strong>GitLens Tips</strong>
<strong>File History View</strong>:
• Right-click file → Show File History
• See when changes were made
• Understand conflict origins
text
<strong>Git Graph Tips</strong> <strong>Visualize Branches</strong>: • Click Git Graph icon in sidebar • See branch structure • Identify merge points • Spot conflict sources <strong>Compare Changes</strong>: • Right-click on commit • Select "Compare with Selected" • View changes side by side <strong class="text-lg">Extension Settings for Better Conflict Handling</strong>
Add these to your VS Code settings (settings.json):
{
// GitLens settings
"gitlens.codeLens.enabled": true,
"gitlens.currentLine.enabled": true,
"gitlens.hovers.currentLine.over": "line",
// Git settings
"git.mergeEditor.diffLayout": "inline",
"git.enableSmartCommit": true,
// Editor settings for conflicts
"editor.renderWhitespace": "all",
"editor.rulers": [80, 120],
"diffEditor.ignoreTrimWhitespace": false
}
``
Extension Keyboard Shortcuts
| Action | Windows/Linux | macOS |
| -------------------------- | ---------------- | ------------- |
| GitLens: Show File History |
Alt+H |
⌥+H |
| Git Graph: View Graph |
Ctrl+Shift+G G |
⌘+Shift+G G |
| Jump to Next Conflict |
Alt+N |
⌥+N |
| Jump to Previous Conflict |
Alt+P |
⌥+P` |
• You need to understand code history
• Want to see who made changes
• Need to compare branches
• You need to visualize branch structure
• Want to see merge history
• Need to understand branch relationships
• You need detailed file history
• Want to compare specific commits
• Need to find when changes were made
• You have multiple conflicts
• Need to navigate between conflicts quickly
• Want keyboard-driven conflict resolution
Remember: These extensions are tools to help you understand and resolve conflicts better. They don't resolve conflicts for you but make the process much more visual and manageable.
Practice Makes PerfectThe best way to learn is by practicing. Try these exercises: