🌿 Chapter 2: Parallel Universes of Branches

Imagine playing an RPG game where you'd definitely "save your progress" before fighting the final boss.
If you lose, you can just reload—no risk of losing your entire account.

The same logic applies to commercial project development. You already have a perfectly functioning website (the main storyline, usually called the main or master branch). Now, your boss asks you to add a "shopping cart" feature.
If you recklessly modify the working files directly, go to sleep mid-task, and wake up to find the website crashed, your boss will definitely lose it.

To solve this problem, Git invented the concept of branches (Branch).
It allows you to create a "parallel universe" where you can experiment and break things without affecting the main storyline.

In this lesson, we'll teach you how to use Vibe Coding thinking to command AI in handling all complex branch operations!


🌌 What is a Branch? How to Create a Parallel Universe?

When you enter the command to create a branch, Git makes a 100% copy of your current project state into a new universe.
Any saves (Commits) you make in this new universe (new branch) will never affect the original main branch.

💡 Vibe Prompt Practice 1: Let AI Teach You How to Create a New Branch

Many people don’t know Git commands or fear typing them wrong. No worries—just describe the scenario to AI!

[!IMPORTANT] Copy and send the following Prompt to AI:

I'm currently on the Git main branch, and the project is working fine.
My boss asked me to develop a new "user login" feature.
Please give me the complete Terminal commands to create a new branch named "feature/user-login" and immediately switch to it.
Explain what these commands mean.

🤖 AI-Generated Real Response & Commands:

# The most modern and recommended approach: use git switch  
git switch -c feature/user-login  

# (Or the older approach, both work the same)  
git checkout -b feature/user-login  

🔍 AI Deep Dive:

  • switch: Means "switch."
  • -c (or -b): Stands for create (create).
  • feature/user-login: The branch name. We prefix it with feature/ to indicate it's a new feature.
  • The full meaning of this command: "Please create a parallel universe called feature/user-login and teleport me there immediately!"

Now, you're in a parallel universe—feel free to modify index.html boldly!


🔀 Switching Between Branches: Traveling Across Universes

While developing feature/user-login, your boss suddenly says: "The logo on the homepage is misspelled! Fix it now!"
What should you do? Your login feature is half-finished, and the code is still broken—you can’t upload it directly.

Don’t panic! Just "switch back to the main universe," create a new emergency fix universe, fix it, then return to the login feature to continue development.

💡 Vibe Prompt Practice 2: Emergency Branch Switching SOP

[!IMPORTANT]
Copy and send the following Prompt to AI:

I'm currently halfway through developing the "feature/user-login" branch, with modified files but unfinished work.
Now I need to urgently switch back to the "main" branch to fix a bug.
Give me a standard Git workflow:
1. How to stage or commit my half-finished files?
2. How to switch back to the main branch?
3. How to create an emergency branch named "hotfix/logo-typo" from main?
Provide the commands and detailed Chinese step-by-step explanations.

🤖 AI-Generated Real Response & Commands:

# Step 1: "Save" the half-finished files in the current universe  
git add .  
git commit -m "chore: login feature in progress (WIP)"  

# Step 2: Safely switch back to the clean main universe  
git switch main  

# Step 3: Split off an emergency fix universe from main  
git switch -c hotfix/logo-typo  

🔍 Deep Dive:
See? This is what senior engineers do daily. As long as you can describe your "situation" and "problem" to AI, it will give you a flawless standard operating procedure (SOP). You don’t need to memorize git stash or other obscure commands—the simplest commit is the best temporary save method.


🗑️ Deleting Unnecessary Parallel Universes

When your emergency fix is done, or a feature gets rejected by your boss, we need to "destroy these useless parallel universes" to prevent our list from growing endlessly.

💡 Vibe Prompt Practice 3: Safely Deleting Branches

[!IMPORTANT]
Copy and send the following Prompt to AI:

I previously created a "feature/old-design" branch, but this design is now scrapped.
Teach me how to delete this local branch using Git.
If I'm currently on this branch, what should I do first before deleting it?
Provide the complete commands.

🤖 AI-Generated Real Response & Commands:

# ⚠️ Note: You can’t "saw off the branch you're sitting on."  
# So first, you must leave the branch to be deleted and switch to main (or another branch).  
git switch main  

# Step 2: Use the -d (delete) command to delete the branch  
git branch -d feature/old-design  

# 【AI Reminder】:  
# If this branch has "unmerged changes," Git will warn and block you from deleting it to protect you.  
# If you’re 100% sure you don’t need these changes, replace lowercase -d with uppercase -D (force delete):  
# git branch -D feature/old-design  

👀 Lost in the Universe? How to View All Branches

After working on a project for a while, you might forget which branches you’ve created or even which universe you’re currently in.

💡 Vibe Prompt Practice 4: Checking the Current State

[!IMPORTANT]
Copy and send the following Prompt to AI:

I'm not sure which Git branch I'm on or what other branches I have.
Give me commands to:
1. List all local branches on my computer and mark where I am.
2. List all branches, including those on the remote server (e.g., GitHub).

🤖 AI-Generated Real Response & Commands:

# 1. List all local branches  
git branch  

# After running, the Terminal will show something like:  
#   feature/user-login  
# * main                  <-- The asterisk (*) means you're here!  
#   hotfix/logo-typo  

# 2. List all local + remote (GitHub) branches  
git branch -a  

🛑 Ultimate Pitfall Guide: Accidentally Developing on the Wrong Branch

This is a pitfall every beginner steps into and a common oversight in Vibe Coding.
You meant to develop on feature/user-login, but forgot to switch and ended up writing a bunch of code directly on main, even modifying 10 files!
By the time you realize it, it’s too late. What now?

Don’t manually delete and rewrite the files! Let AI save you!

💡 Vibe Prompt Practice 5: Time Rescue! Moving Changes to a New Universe

[!IMPORTANT]
Copy and send the following Prompt to AI:

Help! I just made a mistake.
I was supposed to create a "feature/cart" branch to develop a shopping cart.
But I forgot to switch and directly modified 5 files on "main"!
I 【haven’t executed git commit yet】, and the files are in a modified state.
Is there a way to "carry these changes over" to a new "feature/cart" branch while keeping main clean?
Give me detailed commands and explanations.

🤖 AI’s Genius Rescue Commands:

# 🎉 Good news from AI: As long as you haven’t committed, it’s not too late!  
# In Git, uncommitted changes (Modified files) belong to the "working area" and aren’t tied to any branch.  
# So you just need to "carry these changes and jump to a new universe"!  

# Step 1: Directly create and switch to the new branch  
# At this point, the 5 modified files will automatically follow you to the new branch!  
git switch -c feature/cart  

# Step 2: Check the status—you’ll see the changes are here!  
git status  

# Step 3: Now you can safely commit in the new branch  
git add .  
git commit -m "feat: add shopping cart feature"  

🔍 Deep Dive:
This "carry-the-changes" trick is one of Git’s most thoughtful yet unintuitive designs. Many think they’re doomed once they modify files, but asking AI reveals that a single git switch -c can save the day! In the AI era, "accurately describing your disaster scene" is more important than memorizing any rescue commands!


✅ Chapter Summary & Debugging Mindset

In this lesson, you’ve mastered Git’s core "parallel universe" concepts:

  1. Create & switch branches (git switch -c): Always create a new branch for features—don’t dirty main.
  2. Switch branches (git switch): Freely travel between universes.
  3. Delete branches (git branch -d): Destroy unnecessary universes after completing tasks.
  4. Disaster rescue (carry changes): If uncommitted, you can always move changes to a new branch.

Now, you have multiple parallel universes with completed features.
But eventually, we must "merge" these universes back into the main storyline (main).
This merging process is called Merge.

And during merging, the scariest boss appears: "Git Merge Conflicts!"
When you and a colleague modify the same line of code, Git panics—who should it listen to?
Next chapter, we’ll teach you how to elegantly command AI to resolve this bloodbath!

Member Exclusive Free Tutorial

This chapter is free exclusive content for registered members! Please login or register to unlock immediately.

Login / Register Now