Skip to main content
Week 05 • Track 03 • The Process

The Branch
Strategy.

Your site is live. Now you need to add features without breaking it. Git branches let you experiment in a parallel universe.

git log --oneline --graph

* d5a2b3c deploy v1.0 (HEAD -> main)

* e8f1c2d fix mobile nav

* f3a5d7e initial commit

main is safe. This is what users see.

The Mental Model

A soundproof room for experiments.

Imagine your live site is the album that's already on streaming. A branch is a private recording booth where you can experiment without anyone hearing.

main = The Published Album

What users see. Always stable. Never experiment here.

feature branch = The Recording Booth

Your private space. Break things freely. Nobody else sees it.

merge = Release the New Track

When the feature is ready, merge it back into main. Now everyone hears it.

delete branch = Clean Up the Booth

Feature is merged. Delete the branch. Keep the repo tidy.

git log --graph --oneline --all

* f4a1b2c v1.1 live (HEAD -> main)

* e3d9a7f Merge feature/dark-mode

|\

| * a3f2c1d add dark mode toggle

| * b7e9f0a add theme context

| * c1d4e8b install next-themes

|/

* d5a2b3c deploy v1.0

* e8f1c2d fix mobile nav

* f3a5d7e initial commit

main feature/dark-mode merge commit

Branch Basics

Create

Open the Booth

Start a new branch from main. Your experiments begin here.

git checkout -b feature/x
Switch

Change Rooms

Jump between branches. Each has its own version of the code.

git checkout main
Merge

Release the Track

Combine your feature branch back into main.

git merge feature/x
Delete

Clean the Booth

Feature is merged. Delete the branch to keep things tidy.

git branch -d feature/x

The Merge

Two versions become one.

When your feature is ready, you merge it back. Git combines both timelines. Usually this is seamless.

Sometimes two people edit the same line. That's a merge conflict. Git can't decide which version wins—you have to pick.

Clean Merge

No conflicts. Git auto-combines. You're done.

Merge Conflict

Same line edited in both branches. Pick which one to keep.

💡

Pro Tip

Merge main into your feature branch regularly to avoid big conflicts later.

merge-conflict.tsx

<<<<<<< HEAD (main)

backgroundColor: 'white'

=======

backgroundColor: '#0a0a0a'

>>>>>>> feature/dark-mode

// Pick one. Delete the markers.

// Then: git add . && git commit

The Safety Net

🛟

Undo Anything

Git is a time machine. Every commit is a save point. You can always go back.

// Undo last commit (keep changes)

git reset --soft HEAD~1

// Discard all unsaved changes

git checkout .

// Go back to a specific commit

git revert <commit-hash>

🎯

The Naming Convention

Good branch names tell you what's being built at a glance.

feature/dark-mode
fix/mobile-nav-overflow
refactor/extract-user-hook
my-branch
test123
stuff

Common Patterns

Branch Traps

"I'll just code on main"

One bad push and your live site is broken. Always use branches for new work.

"I'll merge when it's 100% done"

Long-lived branches = massive merge conflicts. Merge small and often.

"I don't need branch names"

You will forget what "test2" was for in 3 days. Name descriptively.

"I'll fix the conflict later"

Conflicts compound. Resolve immediately or they snowball.

Clean Branches

One branch per feature

Dark mode gets its own branch. Auth gets its own branch. Never mix.

Pull before you push

git pull origin main first. Make sure you're up to date.

Use PRs for merging

Pull Requests give you a review step before code hits main. Use them even solo.

Delete merged branches

A clean repo has 1-3 active branches, not 47 stale ones.

The Exercises

Practice the branch workflow.

01

The Branch

Create & Switch

  • Create a new feature branch
  • Make a small change and commit
  • Switch back to main—change is gone
Goal: Branches are parallel universes
02

The Merge

Combine Work

  • Switch to main
  • Merge your feature branch
  • Delete the merged branch
Goal: Feature lands in main safely
03

The Conflict

Resolve It

  • Edit the same line on two branches
  • Try to merge—see the conflict
  • Resolve it manually and commit
Goal: Conflicts are normal, not scary

📋 Quick Reference Cheatsheet

New Branch

git checkout -b feature/x

Merge

git merge feature/x

Delete Branch

git branch -d feature/x