The intent-clear replacement for the branch half of checkout.
Switch branches, cleanly. The modern, intent-only replacement for git checkout's branch-switching half. New in Git 2.23.
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.
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>| Flag | What it does |
|---|---|
-c <name> | Create and switch to a new branch. |
-C <name> | Same but force-reset if exists. |
--detach | Detached HEAD at a commit. |
--discard-changes | Throw away local changes that block the switch (rare; usually you stash). |
--orphan <name> | Create a new branch with no parents. |
switch -c spike/x).switch -).$ git switch main$ git switch -c feature/logincd -).$ git switch -$ git switch --detach v1.2git checkout in your fingers and aliases. Within a year you'll wonder why anyone still uses checkout for this.switch - is one of the great quality-of-life flags.switch refuses. Stash, commit, or --discard-changes (knowing what you're losing).switch -c <name> doesn't push the new branch — you still need git push -u origin <name>.Hit each option, then Check answers. Score is recorded; Next is always open.