creation of empty branches
- From
- Angelo Borsotti <angelo.borsotti@gmail.com>
- Date
- Nov 14, 2012, 10:10 UTC
- Message-ID
- <CAB9Jk9CaBECT7c_M9HvCbB8mFYGvdsmq_jFW4DF4NCO8Narnmw@mail.gmail.com>
Hi,
the man page of git checkout does not describe the behavior of git-checkout when asked to create empty branches. E.g.:
$ git init myrepo $ cd myrepo $ git checkout -b newbranch
the last command actually changes only the HEAD. It displays no output telling the user that no switch to a new branch is done. Moreover, it can be entered again without receiving any error message (unlike the creation ot non-empty branches, which is instead rejected). I would suggest to add to the DESCRIPTION, after the paragraph: "If -b is given ...":
"If the repository does not contain any branch, no new branch is created, but the HEAD is set to refer to it."
Moreover, it is often reported (e.g. in the progit book) that git checkout -b is equivalent to git branch; git checkout, and this is true when nonempty branches are created, but it is not when the repository is empty:
$ git init myrepo $ cd myrepo $ git branch master fatal: Not a valid object name: 'master'.
however: $ git checkout -b master .... no error
This seems quite strange and difficult to understand: why should git branch master issue an error while git checkout does not? I have the impression that also git branch should not issue an error in this case.
-Angelo Borsotti