git/list[1] front-page[2] threads[3] people[4] search[5] about
 

creation of empty branches

From
ABAngelo 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
Next: Andrew Ardill
Message 1 of 5 in “creation of empty branches”
  1. Angelo BorsottiNov 14, 2012
  2. Andrew ArdillNov 14, 2012
  3. Junio C HamanoNov 14, 2012
  4. Andrew ArdillNov 15, 2012
  5. Jeff KingNov 15, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.