git-switch
Switch between Git branches
TLDR
Switch to an existing branch
Create a new branch and switch to it
Create a new branch based on an existing commit and switch to it
Switch to the previous branch
Switch to a branch and update all submodules to match
Switch to a branch and automatically merge the current branch and any uncommitted changes into it
SYNOPSIS
git switch [-c|-C] <branch> [--] [<pathspec>...]
PARAMETERS
-c <branch>
Create a new branch named <branch> and switch to it.
-C <branch>
Create a new branch named <branch> and switch to it; starting at <start-point> even if a branch of the same name already exists.
--
Separate branch name from pathspecs.
<pathspec>...
Limits the scope of the operation to the specified paths.
DESCRIPTION
The git switch command is a convenient way to switch between Git branches. It provides a cleaner and more intuitive interface compared to git checkout, especially for branch switching. git switch creates a new branch if one doesn't exist and then switches to it. If a working tree has modifications and those modifications don't affect the files which will be touched by the branch change, it will complete the switch and keep the modifications, otherwise an error will arise until the work tree is clear. The git switch command simplifies branch management and reduces the likelihood of errors associated with git checkout's dual functionality (branch switching and file restoration). Using git switch promotes clarity and reduces ambiguity in git workflows by keeping branch management and file restoration separate.
CAVEATS
Uncommitted changes can prevent branch switching. Stash or commit them before switching.
DETACHED HEAD
git switch is not usable to detach HEAD; use git checkout for that.
HISTORY
git switch was introduced in Git version 2.23 as a more user-friendly alternative to git checkout for switching branches. The goal was to separate branch management from file restoration, a source of confusion with git checkout.
SEE ALSO
git checkout(1), git branch(1), git merge(1)