Git – Create New Branch and Checkout – In One Command

Each time you want to commit a bug or a feature, you need to create a branch for it.

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

After you have created a branch, you need to switch in this branch using a git checkout command.

But it is also possible to create a new Git branch and switch in this branch using only one git checkout command with -b option.

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

Сreate Git Branch and Checkout

Create a new Git branch and checkout:

$ git branch <branch_name>
$ git checkout <branch_name>

Create a Git branch and checkout in one command:

$ git checkout -b <branch_name>

Cool Tip: How to create a new local Git branch from another branch, tag or commit and push it to remote Git repository! Read More →

Was it useful? Share this post with the world!

3 Replies to “Git – Create New Branch and Checkout – In One Command”

  1. Hello,
    Lets say I have develop branch, how do I create new feature branch out of develop branch ? Above way works or is there any other way ? Please help.
    Thanks,
    Sai

  2. If you were currently on master and have just created develop. First, you would have to move to develop if you haven’t already. Once you are in develop, you just need to use the commands above to create the new feature branch.
    In case I haven’t explained myself clear enough, this would be the steps starting in master:

    git checkout -b develop
    git checkout -b newFeature

    OR

    git branch develop
    git checkout develop
    git branch newFeature
    git checkout newFeature

    In both cases, you would end up on your new branch newFeature.
    Hope I could help 🙂
    S. B.

  3. @SAI the above will work. Your new branch will be created off of whatever branch you are currently connected to.

Leave a Reply