git switch
git switch
is a new command designed to replace git checkout
. You can use it to switch between two branches and create new branches. It's more intuitive and easy to use:
Syntax:
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>
Example 1: create a branch based on another local branch
Switch to the base branch:
git switch <branch-name>
Create a new branch, where the option
-c
means to create a new branch.git switch -c <new-branch-name>
Example 2: create a branch based on a branch in an upstream repository
Check out the upstream branch:
git checkout upstream/branch
Create a new branch:
git switch -c <new-branch-name>
For more information, see git switch.