Git – Create New Branch

Instead of committing directly in local master branch, a good developer creates a new branch each time he starts working on a new bug or feature.

To create a new branch there is a git branch command.

Below i will show the examples of how to create a new local branch in Git from another branch (e.g. current branch, master, develop, etc.), how to create a new branch from commit or tag and how to push a new branch to the remote Git repository (create remote branch).

Cool Tip: Create a new Git branch and checkout in one command! Read More →

Create New Branch in Git

Create a new branch from the current branch in Git:

$ git branch <new_branch>

Create a new branch from another branch:

$ git checkout <some_branch>
$ git branch <new_branch>

Create a branch from master:

$ git checkout master
$ git branch <new_branch>

Create a feature branch from develop:

$ git checkout develop
$ git branch feature

Create a new branch from specific commit in Git:

$ git branch <new_branch> <commit>

Create a branch from tag in Git:

$ git branch <new_branch> <tag>

Create a new local branch from the current branch and push it to the remote Git repository (create remote branch in Git):

$ git branch <new_branch>
$ git push -u origin <new_branch>

Cool Tip: Delete remote and local Git branches easily! Read More →

Was it useful? Share this post with the world!

Leave a Reply