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:
- Create a new branch:
git branch feature - List branches to see both:
git branch - Create a second branch:
git branch bugfix - 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.