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

Re: detached HEAD before root commit - possible?

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jun 23, 2013, 23:54 UTC
Message-ID
<20130623235432.GA3024@elie.Belkin>
In-Reply-To
<20130623225505.GO20052@goldbirke>
Hi,
SZEDER Gábor wrote:
Show 7 quoted lines
> $ git init
> Initialized empty Git repository in /tmp/test/.git/
> $ git checkout --detach
> fatal: You are on a branch yet to be born
>
> Are there some plumbing commands and options that would still allow
> this, or can I rely on that that it's impossible?
gitrepository-layout(5) tells me HEAD can be in one of a few states:
 a) Missing.  In this case the repository is considered to be
    corrupt and attempts to access the repository fail until the user
    runs "git init" to recover.
 b) A symbolic link, which is one way to represent a symref (pointing
    to an existing branch or an unborn branch).
 c) A standard symref, in the format "ref: refs/some/branch".  Behaves
    like (b).
 d) A direct SHA-1 reference (40-character commit object name)
    pointing to a commit without associating a branch ("detached HEAD").
 e) Anything else means the repository is corrupt, as in case (a).

In other words, HEAD always either points to an unborn or existing branch or an existing commit. It's not clear to me what it would mean to detach from an unborn branch.

Improvements to the documentation to make that clearer would of course be welcome. ;-)

Thanks, Jonathan

Previous: SZEDER GáborNext: Martin von Zweigbergk
Message 2 of 5 in “detached HEAD before root commit - possible?”
  1. SZEDER GáborJun 23, 2013
  2. Jonathan NiederJun 23, 2013
  3. Martin von ZweigbergkJun 24, 2013
  4. Junio C HamanoJun 24, 2013
  5. Matthieu MoyJun 24, 2013

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.