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

Re: [PATCH v4] doc: checkout: rewrite detached HEAD state explanation

From
Julia Evans <julia@jvns.ca>
Date
Nov 9, 2026, 21:48 UTC
Message-ID
<f7d4600b-909f-4dd7-94da-d525649a9546@app.fastmail.com>
In-Reply-To
<xmqq7bio6jb4.fsf@gitster.g>
On Sat, Nov 7, 2026, at 11:25 PM, Junio C Hamano wrote:
Show 24 quoted lines
> "D. Ben Knoble" <ben.knoble@gmail.com> writes:
>
>> +`HEAD` is where Git stores your current branch or commit. `HEAD` can either be:
>> +
>> +1. A branch, which is your current branch.
>> +2. A commit ID, when you don't have a current branch.
>> +   This is called "detached HEAD state".
>> +
>> +It can sometimes be useful for `HEAD` to be a commit ID, because
>> +it lets you easily check out an old version of your project. For
>> +example, a data scientist could use this to run an old version of a
>> +data pipeline or a programmer could use this to figure out when a bug
>> +was introduced.
>> ...
>> There are some quotes which use the "it's the parent of the next
>> commit" mental model, though, so we could include a comment on that?
>
> "From which your current changes started" is exactly that.  HEAD is
> where you started from (and can come back to, if you get lost after
> botching your working tree state).  Your next commit is built on top
> of it, and then that new commit becomes your current commit.
>
> This is why it is useful for users to realize that HEAD is simply
> where you started from, regardless of where you are going.

I think it's reasonable to try to explain that in both cases there's something in common.

Here's an idea for how to do that:
  
  In Git, you can always use `HEAD` to refer to the current commit.
  But `HEAD` isn't just your current commit: it's also where Git
  stores the name of your current branch. `HEAD` can either be:
  
  1. A branch, which is your current branch.
     The current commit is the latest commit on that branch.
  2. A commit ID, when you don't have a current branch.
     This is called "detached HEAD state".
  
  It can sometimes be useful for `HEAD` to be a commit ID, because...
Show 19 quoted lines
>> The second paragraphs differ a bit, with Junio's containing some bits
>> about clobbering extant branches and not needing temporary branches. I
>> think we could work something in there, like
>> ...
>>     this to figure out when a bug was introduced. By detaching
>>     `HEAD`, you don't need to worry about clobbering an existing
>>     branch or creating a temporary branch.
>>
>> ? I suppose we could also be more explicit ("build, run, and
>> experiment"), if we wanted, but this is a good example to start from.
>
> I assume you mean the last two lines?  I do appreciate that addition.
>
> However, we should avoid saying "useful for HEAD to be a commit ID".
> Being a commit ID is not the notable characteristic of a detached
> HEAD; the fact that it directly refers to a commit is what gives us
> these useful features.  Recording a hexadecimal commit object name
> (instead of a refname of a branch) is a mere implementation detail
> of that direct reference.

Saying "it's a commit ID" is a simple way to say that it directly refers to a commit in a small number of words. I'm not sure what your goal is here, do you think that statement is somehow misleading to users?

Previous: Junio C HamanoNext: Junio C Hamano
Message 26 of 53 in “doc: checkout: rewrite detached HEAD state explanation”
  1. doc: checkout: rewrite detached HEAD state explanationJulia Evans via GitGitGadget, Oct 7, 2026
  2. Junio C HamanoOct 7, 2026
  3. Julia EvansOct 13, 2026
  4. Julia EvansOct 19, 2026
  5. Junio C HamanoOct 19, 2026
  6. Julia EvansOct 20, 2026
  7. Julia EvansOct 20, 2026
  8. Kristoffer HaugsbakkOct 7, 2026
  9. Julia EvansOct 13, 2026
  10. Kristoffer HaugsbakkOct 13, 2026
  11. Julia EvansOct 13, 2026
  12. Julia EvansOct 13, 2026
  13. doc: checkout: rewrite detached HEAD state explanationJulia Evans via GitGitGadget, Oct 13, 2026
  14. Junio C HamanoOct 14, 2026
  15. Julia EvansOct 14, 2026
  16. doc: checkout: rewrite detached HEAD state explanationJulia Evans via GitGitGadget, Oct 15, 2026
  17. Junio C HamanoOct 15, 2026
  18. Julia EvansOct 16, 2026
  19. Junio C HamanoOct 16, 2026
  20. Julia EvansOct 16, 2026
  21. Junio C HamanoOct 16, 2026
  22. doc: checkout: rewrite detached HEAD state explanationJulia Evans via GitGitGadget, Oct 16, 2026
  23. Junio C HamanoOct 16, 2026
  24. D. Ben KnobleNov 7, 2026
  25. Junio C HamanoNov 8, 2026
  26. Julia EvansNov 9, 2026
  27. Junio C HamanoNov 10, 2026
  28. Julia EvansNov 10, 2026
  29. Julia EvansNov 11, 2026
  30. Ben KnobleNov 12, 2026
  31. Junio C HamanoNov 12, 2026
  32. Julia EvansNov 12, 2026
  33. Junio C HamanoNov 12, 2026
  34. Julia EvansNov 12, 2026
  35. Junio C HamanoNov 13, 2026
  36. Julia EvansNov 13, 2026
  37. Junio C HamanoNov 13, 2026
  38. Julia EvansNov 13, 2026
  39. Julia EvansNov 13, 2026
  40. Junio C HamanoNov 14, 2026
  41. Julia EvansNov 14, 2026
  42. Julia EvansNov 13, 2026
  43. Junio C HamanoNov 13, 2026
  44. Julia EvansNov 13, 2026
  45. Junio C HamanoNov 14, 2026
  46. Junio C HamanoOct 16, 2026
  47. doc: checkout: rewrite detached HEAD state explanationJulia Evans via GitGitGadget, Nov 11, 2026
  48. Junio C HamanoNov 11, 2026
  49. Julia EvansNov 12, 2026
  50. Junio C HamanoNov 12, 2026
  51. doc: checkout: rewrite detached HEAD state explanationJulia Evans via GitGitGadget, Nov 12, 2026
  52. doc: add new detached HEAD state guideJulia Evans via GitGitGadget, Nov 16, 2026
  53. Junio C HamanoNov 16, 2026

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.