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.
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.