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?
Join Stack Overflow to learn, share knowledge, and build your career.
|
|
|||||
|
|
In other words
|
||||
|
|
|
It is the short for:
|
|||
|
|
|
|||||
|
|
Full syntax:
The [FROM_BRANCH] is optional. If there's no FROM_BRANCH, git will use the current branch. |
|||
|
|
|
There is also another flag to mention, which is relative to these..
This is a very useful command that i've been using recently. This command checks out the branch you specify, and resets the branch based on the source branch. |
|||||||||||||||||||||
|
|
There are forms of both commands that are similar (looking at git-scm docs Version 2.11.1):
and
The latter executing the branch command first and then adding the checkout. In that form explicitly references to git-branch's doc:
|
|||||
|
|
Essentially : A-git branch lets you create a branch plain and simple. B -git checkout -b allows you to create a branch and switch to it at the same time. When will you use which ? 1- git branch when you want to create a branch but stay on the current branch. 2- git checkout -b when you want to create and switch. If you look at it is intuitive to create a branch and switch to it. So the choice is yours :) |
|||||
|
protected by melpomene Nov 19 '17 at 15:02
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?