Every new feature starts with a single command.
Learning how to create a new branch in Git is one of the first skills developers master when working with source control management.
Branches let you isolate code changes, test ideas safely, and collaborate without breaking production.
Whether you’re building a feature, squashing a bug, or experimenting with a new approach, branching keeps your main codebase clean.
This guide walks through six steps to create local and remote branches using both modern and traditional Git commands.
You’ll learn the git branch, git checkout -b, and git switch -c methods, plus troubleshooting tips when things go wrong.
How to Create a New Branch in Git

Creating a new branch in Git is the process of generating an independent line of development within a repository.
Developers need this when building features, fixing bugs, or experimenting without affecting the main codebase.
This guide covers 6 steps requiring 2-3 minutes and basic command line knowledge.
Prerequisites
- Git 2.23 or later (for
git switch) or any version (forgit checkout) - Existing local or cloned repository
- Terminal, Git Bash, or command line access
- Basic familiarity with version control commands
- Time estimate: 1-2 minutes
Step One: How Do You Check Your Current Branch?
Run git branch or git status in your terminal to display which branch you’re currently on.
The active branch shows an asterisk () next to its name.
Your new branch will inherit all commits from this starting point, so confirming your position matters.
Action
- Terminal: Navigate to your project directory
- Command:
git branchorgit status - Result: Current branch marked with (e.g.,
* main)
Purpose
The HEAD pointer determines where your new branch starts; checking it first prevents creating branches from the wrong base.
Step Two: How Do You Create a New Branch Without Switching?
The git branch command creates a new branch pointer without moving your working directory to it.
Use this method when you want to create multiple branches before deciding which one to work on.
Action
- Command:
git branch feature-login - Naming convention: Use prefixes like
feature/,bugfix/, orhotfix/ - Result: Branch created, HEAD stays on current branch
Purpose
Separates branch creation from switching branches, giving you control over when to start working on new code.
Step Three: How Do You Create and Switch to a New Branch at the Same Time?
Most developers prefer creating and switching in one command since they typically want to start working immediately.
Two commands accomplish this: git switch -c (modern) and git checkout -b (traditional).
Action
- Modern method:
git switch -c feature-signup - Traditional method:
git checkout -b feature-signup - Result: Branch created and HEAD moves to new branch
Purpose
Combines two operations into one, saving time during software development workflows where feature branches get created frequently.
Step Four: How Do You Create a Branch From a Specific Commit?
Creating a branch from a specific commit hash lets you start development from any point in your project history.
Useful for hotfixes on older releases or recovering work from previous states.
Action
- Find commit hash:
git log --oneline - Command:
git branch hotfix-v2 a1b2c3d - Result: Branch starts from specified commit, not current HEAD
Purpose
Lets you branch from historical commits when fixing bugs in production releases without pulling in newer, untested code.
Step Five: How Do You Create a Branch From Another Branch?
Sometimes you need a branch based on a feature branch rather than main.
Specify the source branch name after your new branch name to set a different starting point.
Action
- Command:
git checkout -b feature-auth develop - Alternative:
git switch -c feature-auth develop - Result: New branch based on
developinstead of current branch
Purpose
Supports Git Flow and other branching strategies where features branch from develop, not main.
Step Six: How Do You Push Your New Branch to a Remote Repository?
Local branches exist only on your machine until you push them to a remote repository like GitHub or GitLab.
The -u flag establishes tracking between local and remote branches.
Action
- Command:
git push -u origin feature-login - The
-uflag: Sets upstream tracking connection - Result: Branch visible on remote, future pushes simplified to
git push
Purpose
Makes your branch available for code review, pull requests, and collaboration with other developers.
Verification
Confirm your branch was created correctly with these Git commands:
git branch -a: Lists all local and remote branches- git log
--oneline: Confirms branch points to expected commit git branch -r: Verifies remote branch exists after pushing
Troubleshooting
Branch Name Already Exists
Issue: Git returns “fatal: A branch named ‘feature-x’ already exists.”
Solution: Choose a different name or rename the existing branch with git branch -m old-name new-name.
Cannot Switch With Uncommitted Changes
Issue: Git blocks switching when you have uncommitted modifications.
Solution: Run git stash before switching, then git stash pop after.
Branch Not Appearing on Remote
Issue: Pushed branch doesn’t show on GitHub or GitLab.
Solution: Verify remote with git remote -v; confirm origin points to correct URL.
Alternative Methods Comparison
| Method | Command | Git Version | Best For |
| Switch Shortcut | git switch -c <name> | 2.23+ | Daily work; modern, safe, and intuitive branch creation. |
| Checkout Shortcut | git checkout -b <name> | All Versions | Legacy scripts and users with deep muscle memory. |
| Standard (2-Step) | git branch + git switch | All Versions | Creating a branch to work on later without leaving your current task. |
| Orphan Switch | git switch --orphan <name> | 2.23+ | Creating a branch with no history (e.g., for documentation/gh-pages). |
Use git checkout -b for maximum compatibility across environments.
Use git switch -c if your team runs Git 2.23 or newer.
Related Processes
- How to merge two branches in Git
- How to delete a branch in Git
- How to resolve merge conflicts in Git
- How to clone a Git repository
FAQ on How To Create A New Branch In Git
What is the command to create a new branch in Git?
Use git branch branch-name to create a branch without switching, or git checkout -b branch-name to create and switch simultaneously.
Git 2.23+ users can also run git switch -c branch-name for the same result.
What is the difference between git branch and git checkout -b?
The git branch command only creates the branch pointer.
The git checkout -b command creates the branch and moves HEAD to it in one step, saving you from running a separate fetch or checkout afterward.
How do I create a branch from a specific commit?
Run git branch branch-name commit-hash using the first 7-8 characters of your target commit.
Find commit hashes with git log --oneline. This creates a branch starting from that historical point in your repository.
How do I push a new local branch to a remote repository?
Execute git push -u origin branch-name to upload your local branch.
The -u flag sets up tracking, so future push and pull commands work without specifying the remote.
Can I create a branch from another branch besides main?
Yes. Use git checkout -b new-branch source-branch to base your new branch on any existing branch.
This is standard practice in Git workflows where features branch from develop instead of main.
What is the best naming convention for Git branches?
Use prefixes like feature/, bugfix/, hotfix/, or release/ followed by a descriptive name.
Keep names lowercase with hyphens: feature/user-authentication. Avoid spaces and special characters.
How do I check which branch I am currently on?
Run git branch to list all local branches with an asterisk marking your current one.
Alternatively, git status shows your current branch at the top of its output along with staging information.
Why can’t I switch branches with uncommitted changes?
Git protects uncommitted work from being overwritten during branch switches.
Either commit your changes, stash them with git stash, or discard them with git checkout -- . before switching.
How do I create a branch from a tag?
Use git checkout -b branch-name tag-name to create a branch starting from a specific tag.
Tags mark release points, so this method works well for creating hotfix branches from production versions.
What happens if I create a branch with a name that already exists?
Git returns an error: “fatal: A branch named ‘x’ already exists.”
Either choose a different name, delete the existing branch with git branch -d branch-name, or rename it using git branch -m.
Conclusion
Knowing how to create a new branch in Git is a core skill for any developer working with distributed version control.
You now have multiple methods at your disposal: git branch, git checkout -b, and git switch -c`.
Each serves the same purpose with slight differences in workflow.
Branching supports clean feature-driven development, safer bug fixes, and smoother collaboration between dev and ops teams.
It integrates directly into continuous integration pipelines and modern DevOps practices.
Start with the basics. Create feature branches for every new task.
Push them to your remote for backup and review. Delete them after merging.
This habit keeps your repository organized and your commit history readable.
- How to Make a Repository Public in GitHub - July 14, 2026
- Production Incident Communication Without Separate Monitoring and Status-Page Systems - July 13, 2026
- How to Set Up Subscriptions on Google Play (Developer Guide) - July 12, 2026



