Coding for All
Level 5: Switching Branches
Switching Branches Move onto a branch and commit there with git switch.

To work on a branch, you switch to it: git switch feature moves HEAD, the "you are here" marker, onto that branch. Any commit you make now lands on feature, not main.

Because create-then-switch is so common, modern git has a shortcut: git switch -c robot creates the branch and moves you onto it in one go. (If you've seen git checkout in old tutorials, switch is its modern, clearer replacement.)

Make a branch called robot, get onto it, and commit something. Watch main stay exactly where it is.

git switch <name>Moves HEAD onto an existing branch.
git switch -c <name>Creates a branch and switches to it, in one command.
git commit -m "message"Commits now land on the branch you are on.
Your task

Move onto a branch and commit there with git switch.

Open this level in your browser to type the commands at a live git prompt with an animated commit graph.