6

What is git checkout -b <branchname> for ?

I mean, you can create a branch by doing git branch <branchname>

but, what it does git checkout -b <branchname> specifically ?

Non
  • 8,409
  • 20
  • 71
  • 123
  • A quick quote from the documentation of [`git checkout`](http://git-scm.com/docs/git-checkout): *"Specifying `-b` causes a new branch to be created as if [`git-branch`](http://git-scm.com/docs/git-branch) were called and then checked out."* – axiac Aug 18 '15 at 19:21

1 Answers1

16

That means you do two things:

  1. Create a new branch <branchname>
  2. Checkout the new branch <branchname>

It's simply shorthand for creating a new branch and then directly checking it out.

$ git checkout -b new-feature

Is shorthand for and the equivalent of:

$ git branch new-feature
$ git checkout new-feature

For reference, please see the documentation on git-branch.

Thomas Stringer
  • 5,682
  • 3
  • 24
  • 40