Git new branch
A common Git command!
git branch
is used to create a new branch in your Git repository. Here are a few ways to use it:
Create a new branch
git branch <branch-name>
Replace <branch-name>
with the name you want to give your new branch. For example:
git branch feature/new-login-system
This will create a new branch called feature/new-login-system
that is based on the current branch (usually master
).
Create a new branch and switch to it
git branch <branch-name> && git checkout <branch-name>
This will create the new branch and immediately switch to it. For example:
git branch feature/new-login-system && git checkout feature/new-login-system
Create a new branch from a specific commit
git branch <branch-name> <commit-hash>
Replace <commit-hash>
with the hash of the commit you want to base your new branch on. For example:
git branch feature/new-login-system 123456
This will create a new branch called feature/new-login-system
that is based on the commit with hash 123456
.
Create a new branch from a specific branch
git branch <branch-name> <existing-branch-name>
Replace <existing-branch-name>
with the name of the branch you want to base your new branch on. For example:
git branch feature/new-login-system master
This will create a new branch called feature/new-login-system
that is based on the master
branch.
That's it!