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.

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.

Practice

A real repo, pre-seeded with history, runs right here — stage, commit, branch, stash, diff, even hit and resolve a real merge conflict. Nothing to install, nothing leaves your machine.

Open practice playground

Go deeper with