1. Create and switch in one step
git checkout -b feature-login
The -b flag tells Git to create the branch before switching. You are now on feature-login and any commits go there.
2. The modern way with git switch
git switch -c feature-login
git switch was added to make branch commands easier to read. The -c flag means create.
3. Create a branch without switching
git branch feature-login
This creates the branch but leaves you where you are. Switch to it later with git switch feature-login.
4. Push the new branch to the remote
git push -u origin feature-login
The -u flag links your local branch to the remote one, so future git push and git pull commands need no extra arguments.
Which command should you use?
- git switch -c — the clearest modern choice for create-and-switch.
- git checkout -b — the classic command; works everywhere.
- git branch — when you want to create a branch but stay put.
Frequently asked questions
How do I see all my branches?
Run git branch to list local branches; the current one is marked with an asterisk. Add -a to include remote branches.
How do I delete a branch I no longer need?
Use git branch -d feature-login for a merged branch, or -D to force-delete one that is not merged.
New to version control? See our complete guide to learning to code.