Progress:
TIER 1 · MODULE 16· Basics

git switch

The intent-clear replacement for the branch half of checkout.

🎯 What & why

Switch branches, cleanly. The modern, intent-only replacement for git checkout's branch-switching half. New in Git 2.23.

🧠 Mental model

switch <name> updates HEAD to point at branch <name> and updates the working tree to match. That's it — no path-restoring side missions, no overloaded behavior.

🛠️ Synopsis

git switch [<options>] [--no-guess] <branch>
git switch [<options>] --detach [<start-point>]
git switch [<options>] (-c | -C) <new-branch> [<start-point>]
git switch [<options>] --orphan <new-branch>

🎚️ Switches & options

FlagWhat it does
-c <name>Create and switch to a new branch.
-C <name>Same but force-reset if exists.
--detachDetached HEAD at a commit.
--discard-changesThrow away local changes that block the switch (rare; usually you stash).
--orphan <name>Create a new branch with no parents.

💡 Use cases

🧪 Examples

Switch to an existing branch.
$ git switch main
Create and switch.
$ git switch -c feature/login
Switch back to the previous branch (like cd -).
$ git switch -
Detached HEAD at a tag.
$ git switch --detach v1.2

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.