adrienjoly adrienjoly - 1 year ago 79
Git Question

What is the difference between "git branch" and "git checkout -b"?

I used

git checkout -b
to create a new branch. I think that
git branch
does the same thing.
How do these two commands differ, if they differ at all?

Answer Source

git checkout -b BRANCH_NAME creates a new branch and goes to the new branch while git branch BRANCH_NAME creates a new branch but leaves you on the same branch.

In other words git checkout -b BRANCH_NAME does the following for you.

git branch BRANCH_NAME    # create a new branch
git checkout BRANCH_NAME  # then switch to the new branch
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download