How do I create a new branch in Git?
There are two ways. git branch only creates the branch, and git switch -c creates it and moves you to it.
Terminal output
$ git branch feature-cart
$ git switch -c feature-search
Switched to a new branch 'feature-search'
$ git branch
feature-cart
* feature-search
main
The old command git checkout -b feature-search does the same as git switch -c. A new branch starts from the commit where you are now. See Git Branch.
Learn more about the similar topics:
| Tutorials |
|---|
| Git Branch |
| Git Checkout and Switch |
| Git Merge |
| Git Merge Conflict |
| Git Rebase |
| Git Cherry Pick |
| Git Branching Strategy |