⚔️ Chapter 3: Battling the Final Boss (Git Merge & Conflict Resolution)
In the previous chapter, we learned how to develop new features in parallel universes (Branches).
When you've perfected the shopping cart in the feature/cart branch and tested it thoroughly, the next big moment is: "Merging the shopping cart functionality back into the main main universe."
If your code doesn't overlap with your colleague's changes on the same lines, merging is usually instantaneous.
But what if...
You modified line 10 of index.html.
Your colleague also modified line 10 of index.html.
When you attempt to merge, Git will crash with red text, screaming Merge Conflict!
Fear not! Handling conflicts is part of an engineer's daily routine. In this lesson, we'll teach you how to resolve these bloody battles elegantly the Vibe Coding way.
🤝 Peaceful Fusion: The Most Basic Merge Operation
First, let's learn the perfect merge workflow for when there are no conflicts.
💡 Vibe Prompt Practice 1: Safe Merge Standard Operating Procedure (SOP)
Don't type commands randomly—when dealing with important merges, ask AI for the SOP directly!
[!IMPORTANT] Copy and send this Prompt to AI:
I've completed development on the "feature/cart" branch and executed git commit.
Now I want to merge this branch's code back into the "main" branch.
Please provide me with a safe standard command flow and teach me how to delete "feature/cart" after merging.
🤖 AI's Actual Response & Commands:
# Step 1: First, switch back to the "receiver" universe (i.e., main)
git switch main
# Step 2: Execute the merge command to absorb the essence of feature/cart
git merge feature/cart
# Step 3: (Optional) If the merge succeeds without errors, delete the now-unused dev branch
git branch -d feature/cart
🔍 Deep Dive:
Merging is like "a big fish eating a small fish." You must first become the big fish (switch main) before devouring the small fish (merge feature/cart). Many people reverse the order, executing merge main from the dev branch, and end up in chaos!
💥 Disaster Strikes: Deciphering Merge Conflict's Terrifying Symbols
When you run git merge, if the terminal shows this:
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.
Congratulations! You've hit the jackpot.
If you open index.html, you'll see your code littered with what looks like gibberish:
<<<<<<< HEAD
<button class="bg-blue-500">Normal Login</button>
=======
<button class="bg-red-500">Google Login</button>
>>>>>>> feature/google-login
This isn't malware—it's Git crying for help!
💡 Vibe Prompt Practice 2: Let AI Translate Conflict Symbols
[!IMPORTANT] Copy and send this Prompt to AI:
I just encountered a conflict during git merge.
I opened the file and saw these weird symbols: <<<<<<< HEAD, =======, >>>>>>>.
In plain terms, what do these three symbols mean?
Then tell me how I should handle this text.
🤖 AI's Layman Explanation:
These symbols are Git's "dividers," showing where the two sides disagree:
1. Between <<<<<<< HEAD and =======:
This is the code from 【your current branch (usually main)】—what the file originally looked like.
2. Between ======= and >>>>>>> feature/google-login:
This is the code from 【the branch being merged (the small fish)】.
💡 Your Mission (Conflict Resolution):
You must act as the judge.
1. Manually delete the weird symbols (<<<<, ====, >>>>).
2. Decide which code to keep—or modify both to merge their strengths.
3. Save, then re-run `git add` and `git commit`.
🤖 AI Arbitrator: Throw the Whole File at AI to Resolve Conflicts
If you can't spot the differences between the conflicting code or want to preserve the best of both worlds, the smartest move is:
"Copy-paste the conflict-laden code to AI and let it rewrite a clean version for you!"
💡 Vibe Prompt Practice 3: Let AI Solve Complex Conflicts
[!IMPORTANT] Copy and send this Prompt to AI:
I encountered a Git conflict in index.html. Here's the raw code with conflict markers:
<<<<<<< HEAD
<div class="header">Welcome to Vibe Tutor (Blue Theme)</div>
=======
<div class="header" id="main-title">Welcome to Vibe Tutor - Enhanced</div>
>>>>>>> feature/new-title
Please resolve this conflict.
My requirements: Keep the id="main-title" and "- Enhanced" from feature/new-title, but also preserve the "(Blue Theme)" text from HEAD.
Give me the final clean HTML code without any Git symbols.
🤖 AI's Perfectly Arbitrated Code:
<!-- AI merged both requirements flawlessly and removed all ugly symbols -->
<div class="header" id="main-title">Welcome to Vibe Tutor - Enhanced (Blue Theme)</div>
🔍 Deep Dive:
In the Vibe Coding era, you no longer need to hunt for deletions in braces and tags. Just describe what you want to keep, and AI delivers a perfect hybrid in seconds. Paste this clean code back into VSCode, save, and you're done!
😅 The Undo Pill: How to Abort This Terrifying Merge
Sometimes conflicts are overwhelming (e.g., dozens of files conflicted). You’re dizzy and think,
"I don’t want this merge anymore! Take me back to pre-merge state!"
Git offers the ultimate "undo pill."
💡 Vibe Prompt Practice 4: Abort Merge and Escape
[!IMPORTANT] Copy and send this Prompt to AI:
I just ran git merge, but there are too many conflicts. I don’t want to deal with this.
Teach me how to "abort this merge" and revert my project to its pre-merge state.
Provide the command.
🤖 AI's Actual Response & Command:
# This is the ultimate undo pill!
# As long as you're still in merge conflict state (no commit yet), run:
git merge --abort
# Your project will time-travel back to the moment before git merge!
# All <<<<<< HEAD symbols will vanish instantly.
🛠️ VSCode's God-Tier Built-In Feature
Modern editors like VSCode or Cursor have turned conflict resolution into a one-click interface.
When you open a conflicted file in VSCode, you’ll see four small buttons (Code Lens) above the <<<<< HEAD markers:
- Accept Current Change (Keep HEAD’s version)
- Accept Incoming Change (Keep the merging branch’s version)
- Accept Both Changes (Keep both and manually adjust)
- Compare Changes (Side-by-side diff view)
💡 Vibe Prompt Practice 5: Ask About Editor Tricks
[!IMPORTANT] Copy and send this Prompt to AI:
I'm using VSCode to handle a Git Merge conflict.
I see "Accept Current Change" and "Accept Incoming Change" buttons.
In VSCode, what does "Current" refer to? What about "Incoming"?
If I click the wrong button, how do I undo?
🤖 AI's Pro Guidance:
- Current: Refers to
HEAD—the universe you’re merging into (usuallymain). - Incoming: Refers to the parallel universe being merged in.
- If you misclick, just hit
Ctrl + Z(Mac:Cmd + Z) to undo immediately!
✅ Chapter Summary & Debugging Mindset
After this lesson, you should feel excitement—not fear—when facing Git Merge conflicts!
- SOP: Always
switch mainfirst, thenmergeothers. - Decipher Symbols:
HEADis the original; the other is the newcomer. - Ultimate Solution: Copy-paste conflicts to AI, specify what to keep, and paste back clean code.
- Escape Plan: Messed up?
git merge --abortfor instant time travel.
With branching and conflict resolution mastered, your local (Local) development skills are complete.
Next up: Chapter 4: Free Deployment! GitHub Pages Secrets, where we’ll teach you to push your code to the cloud and turn it into a live website—for free!