Cheat Sheets · Git Cheat Sheet · Git Switch Branch — Modern Branch Navigation

Git Switch Branch — Modern Branch Navigation

git switch <branch>

Switch to an existing local branch

git switch -c <new-branch>

Create and switch to a new branch (replaces checkout -b)

git switch -

Switch back to the previous branch you were on

git switch --detach <sha>

Switch to a specific commit in detached HEAD state

Switch branch patterns

CommandAction
git switch <branch>Switch to an existing local branch
git switch -c <new-branch>Create and switch to a new branch (replaces checkout -b)
git switch -Switch back to the previous branch you were on
git switch --detach <sha>Switch to a specific commit in detached HEAD state

Introduced in Git 2.23, git switch replaces git checkout for branch switching, eliminating the confusion of mixing file restoration with branch checkout.

Related Git recipes

FAQ

Why was git switch introduced?
git checkout handled both branch navigation AND file reverting. Git 2.23 split these into git switch (branches) and git restore (files).

What does git switch - do?
The hyphen - switches to whatever branch you were on previously — exactly like cd - in bash.

What if I have uncommitted changes?
If your changes do not conflict with the target branch, Git carries them over. If there are conflicts, Git halts and asks you to stash or commit first.

Stop memorizing — build it interactively

Build branch workflows in the Git Builder

Full reference: Git Cheat Sheet