git switch
The modern, focused way to change branches.
git switchWhat it does
git switch (Git 2.23+) is the same HEAD-moving mechanism as git checkout, stripped of the file-restoring half. It only changes which branch you're on — no accidental intent mixing, no hidden file-revert foot-guns.
git switch only moves HEAD between branches — nothing else
Watch it — press play
A narrated, step-by-step walkthrough that shows how to do it — not just theory. It adapts to the learner mode you picked in the top bar.
Step 1
A focused checkout
SWITCH is checkout's branch-only half. One job: move HEAD between branches.
git switch featureUnder the hood
Purely a HEAD + worktree operation
Like checkout, switch rewrites .git/HEAD and synchronizes the working tree. The difference is conceptual: the command refuses to guess about files, keeping one job per command.
-c creates, then switches
`git switch -c feat` is two steps under the hood: `git branch feat` (write the ref file) followed by switching HEAD to it. Identical to checkout -b, but scoped and predictable.
Aliases the pros type
Memorize the git switch concept, then let one of these shortcuts make it instant. Aliases are real git config keys — add one with:
git config --global alias.st # → git switchg swgit switchThe oh-my-zsh default.
g swcgit switch -cCreate a branch and jump onto it.
g sw -git switch -Flip back to the last branch you were on.
Command anatomy
-c <name>Create the branch, then switch to it.
-Switch to the previously checked-out branch (toggle).
-fDiscard local changes and switch anyway.
-t <remote/branch>Create a local branch that tracks the given remote one.
When to reach for it
Your daily branch-jumping — cleaner intent than checkout.
Quickly bouncing between two branches with `git switch -`.
Onboarding: newcomers learn switch + restore, never the legacy checkout split.
Pro tip
`git switch -` pairs beautifully with stashing: save work on branch A, flip to branch B with `g sw -`, and flip back anytime. HEAD toggling is instant — it's just rewriting one text file plus restoring blobs.