Home

GIT - Creating new branch using GIT CLI

Creating a new branch

If you want to just create a new branch (out of current branch), run the following command:

git branch <new_branch_name>

The above command will create a new branch with new_branch_name, but you will remain in the current branch. Then to move to the new branch you need to use

git checkout <new_branch_name>

Creating and switching to the new branch

If you want to create and switch to the newly created branch then use:

git checkout -b <new_branch_name>

Creating branch out of another branch ( and switching to newly created)

Use this command to create a branch from another branch which is different from your current.

git checkout -b <new_branch_name> <another_branch_name>

Explanation: Generally you will create a branch from your master. For e.g., when you are on master, you should run git checkout -b feat-add-btn to create feat-add-btn branch from the current branch (master). But if you want to create a branch(say fix-primary-btn) from another branch(let's say dev) while you are on master, then you need to run git checkout -b fix-primary-btn dev.



Last Updated on

Next Post: GraphProtocol: TS2322 null assignment in Subgraph →

Comments