Create branches
Experiment safely
⏱ Est. ~7 min
01 · Read
A branch lets you build a new feature or experiment without affecting the project's main version. You create a branch, work on it, then merge it back when you're done.
💡 Picture thisCreating a branch is like making a photocopy of your photo album to experiment on. You can doodle, rearrange pages, try out wild ideas. If it works out, you merge the changes back into the original. If it doesn't, you just throw the copy away.
Key points
- git checkout -b branch-name creates a new branch and switches to it
- git branch lists all branches and marks the one you're on
- Branches keep experimental work separate from the stable main branch
02 · Terminal exercise
Before we can branch, we need a repo with a commit. Set that up first.
(This section is interactive — please enable JavaScript.)
03 · Terminal exercise
Stage all the files for our first commit.
(This section is interactive — please enable JavaScript.)
04 · Quiz
What does git checkout -b feature do?
- Deletes the branch called 'feature'
- Creates a new 'feature' branch and switches to it
- Switches to an existing 'feature' branch
- Merges 'feature' into main
05 · Terminal exercise
Make the first commit so we have a starting point to branch from.
(This section is interactive — please enable JavaScript.)
06 · Terminal exercise
A branch is another copy of your project where you can experiment without affecting the original. git checkout -b creates a branch and switches to it — one command.
(This section is interactive — please enable JavaScript.)
07 · Terminal exercise
Let's look at all branches in this repo.
(This section is interactive — please enable JavaScript.)
08 · Fill in the blank
To create a new branch called login-page and switch to it in one command, type: git checkout ___ login-page
Other lessons in this chapter
⚠ The full interactive experience needs JavaScript. Please enable it and reload.
※ This is an independent Traditional Chinese teaching project — not an official Anthropic product. Claude™ is a trademark of Anthropic, PBC.