Back to roadmap

Lesson 05

Branches

A branch is a movable name for a line of commits. Creating one names a path; it does not switch you to it.

Visual Explanation

Ready to run git branch feature/login.

Keep These Ideas

Branch Pointer
A branch names one commit and moves forward when you commit on it.
Create, Don't Switch
git branch creates the name. HEAD remains on your current branch.
No new commit
Creating a branch adds a name at an existing checkpoint; history does not grow yet.

The Real Command

Terminal
git branch feature/login

git branch feature/login creates a branch pointer at your current commit without switching to it.

Command Details

git branch

The * marks your current branch. It is output from Git, not a character you type.

Example Output
  feature/login
* main
git branch --list "feature/*"

* is a wildcard here. The quotes keep the pattern together while Git lists matching branch names.

Example Output
  feature/login
git branch -d feature/login

-d deletes a safely merged branch. Git refuses when the branch contains work that has not been merged.

Knowledge Check

Name a Separate Path

Create and inspect branch names without confusing creation with switching.

Question 1 of 5

  1. Question 1: current
  2. Question 2: not started
  3. Question 3: not started
  4. Question 4: not started
  5. Question 5: not started
Command Challenge

Create a branch named feature/login without switching away from main.