How to create a new branch and switch to it with checkout?

git checkout -b new_branch

To create a new branch and switch to it in one command use git checkout -b new_branch, where new_branch is the name of the new branch.

Layer 1
Terminal Example
git status
On branch main
nothing to commit, working tree clean

git checkout -b new_branch
Switched to a new branch 'new_branch'

git status
On branch new_branch
nothing to commit, working tree clean

See git checkout to learn more about it.

Last modified on November 30, 2021.

You might also like