LESSON 6

Branches

Learning objective: Work on features safely using branches.

Understand

Branches let you work without affecting the main code.

A branch is a separate line of work. Create one for each feature so the main branch stays stable. Switch between branches with git switch (or git checkout).

Analogy: A branch is like a sandbox copy where you can experiment without breaking the real thing.

See It in Action

Creating and switching:

git branch feature-nav
git switch feature-nav
How it works: The first line creates a branch and the second moves onto it, so new commits do not touch main.

Try It Yourself

  1. Create a new branch.
  2. Switch to it.
  3. Make a commit on the branch.

Quick Quiz

Why use branches?

Challenge

Create a feature branch and make a commit on it.

Success condition: Your commit lives on a branch separate from main.