All commands

git switch

The modern, focused way to change branches.

What 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.

9a2f1c0init project4b7c2a5add componentsfeature74d3b9ffeat: dark modemainHEAD

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.

1 / 3

Step 1

A focused checkout

SWITCH is checkout's branch-only half. One job: move HEAD between branches.

git switch feature
9a2f1c0init project4b7c2a5add componentsfeaturec86d9eestyle layoutmainHEAD

Under the hood

1

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.

2

-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 switch
AliasWhy people use it
g sw

The oh-my-zsh default.

g swc

Create a branch and jump onto it.

g sw -

Flip back to the last branch you were on.

Command anatomy

git switch <branch>
-c <name>

Create the branch, then switch to it.

-

Switch to the previously checked-out branch (toggle).

-f

Discard 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.

Go deeper with