git switch
Switch to a specified branch. The working tree
and the index are updated to match the branch.
All new commits will be added to the tip of this
branch.
Switching branches does not require a clean index
and working tree (i.e. no differences compared to
HEAD).
-c
is a convenient shortcut for:
$ git branch <new-branch>
$ git switch <new-branch>
Examples
You can grow a new branch from any commit. For
example, switch to “HEAD~3” and create branch
”fixup”:
$ git switch -c fixup HEAD~3
Switched to a new branch 'fixup'
If you want to start a new branch from a remote
branch of the same name:
$ git switch new-topic
Branch 'new-topic' set up to track remote branch 'new-topic' from 'origin'
Switched to a new branch 'new-topic'
If it turns out whatever you have done is worth
keeping, you can always create a new name for it
(without switching away):
$ git switch -c good-surprises