This command simplifies starting work on a new feature by creating and checking out a new branch in a single step.
The -c
flag tells Git to create the new branch and immediately switch to it, while git switch
itself handles branch switching; <branchname>
is a placeholder for whatever name you choose for the new branch.
Variations include using the long form --create
instead of -c
, omitting -c
to switch to an existing branch (git switch <branchname>
), or using the older equivalent command git checkout -b <branchname>
; you can also add --force
to overwrite an existing branch if it already exists.
Examples:
git switch -c my-feature
git switch -c bugfix/fix-crash