Tour of Git
Branching & Merging / Lesson 2.2

git branch — Creating Branches

The git branch command lets you create, list, rename, and delete branches.

Creating a Branch

git branch feature

This creates a new branch called feature pointing at the current commit. It does not switch to it — you stay on your current branch.

Listing Branches

git branch

Shows all local branches. The current branch is marked with *.

Deleting a Branch

git branch -d feature

Deletes a branch that has been fully merged. Use -D (capital) to force-delete an unmerged branch.

Renaming a Branch

git branch -m old-name new-name

Try it!

Your repo has one commit on main. Your task:

  1. Create a new branch: git branch feature
  2. List branches to see both: git branch
  3. Create a second branch: git branch bugfix
  4. Check the branch list again: git branch

Watch the graph — all three branches point to the same commit because no new commits have been made yet.

Key Insight

Creating a branch is cheap and instant — it's just a 41-byte pointer. Branch early, branch often.

🎯

Goal

Create two new branches: 'feature' and 'bugfix'

Terminal
$

No commits yet. Run `git init` and create your first commit.