Skip to content
Branching and merging

Starting a branch

Create and switch, in the modern spelling.

`git switch -c <name>` creates a branch at the current commit and moves onto it. `git branch <name>` creates without moving, which is occasionally what you want and usually not.

`switch` and `restore` were introduced to split the two unrelated jobs `checkout` had been doing for years. `checkout` still does both, which is why it is confusing; the newer commands each do one thing.

Switching branches replaces your index and working tree with the target's — unless that would overwrite an uncommitted change, in which case git refuses rather than losing it.

Commands in this lesson

git switch
Move HEAD to another branch, and with -c create it first
git branch
List, create or delete the names that point at commits
No account, no backend. Everything you do stays in this browser.liter8.sh