What is the difference between the git checkout devel and git checkout –b devel commands?
|
2 answers
To create a branch and go straight to it, you can run the git checkout command with the -b :
$ git checkout -b dev This is an abbreviation for:
$ git branch dev $ git checkout dev More details can be found here: Branching in Git
|
The difference is that:
- with the
-boption, thecheckoutcommand will first try to create the specified branch (git branch ветка), and, if the branch already exists, will return an error:fatal: A branch named 'branch' already exists.
- without the
-boption, there will be no preliminary attempt to create a branch, therefore, if such a branch does not exist yet, an error will be returned:error: pathspec 'branch' did not match any file (s) known to git.
simple rule:
if the branch already exists, use it to switch to it
$ git checkout веткаif the branch does not exist, use it to create and switch to it:
$ git checkout -b ветка
|
develbranch - Ihor Tkachuk