git switch
Switches to a specified branch. Introduced in Git 2.23 as a safer alternative to git checkout for branch switching.
Syntax
git switch [<options>] <branch>
Options
- -c / --create <branch>: Creates a new branch and switches to it
- -C: Creates or resets a branch and switches to it
- --detach: Switches to a commit in detached HEAD state
- -: Switches to the previously checked out branch
Example
git switch main git switch -c feature/new git switch -