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

Branch information (git branch/status) inconsistent when in detached HEAD state

From
SRStijn De Ruyck <stijn.deruyck@onsemi.com>
Date
Oct 6, 2015, 13:03 UTC
Message-ID
<247ABEF3B84FB7499C074A0FE8058694153CB176@ONWATER51M.ad.onsemi.com>
Hello,

Consider a repository with a develop branch tracking origin/develop and where HEAD = 545a36f = develop = origin/develop. Tested with Git 2.4.3 and 1.8.3.4 on Linux.

1) git checkout develop
2) git branch | head -1 (or git status)
* develop
3) git checkout origin/develop
Note: checking out 'origin/develop'.
You are in 'detached HEAD' state.
4) git branch | head -1
* (HEAD detached at origin/develop)
5) git checkout 545a36f
6) git branch | head -1
* (HEAD detached at origin/develop)
7) git checkout develop
8) git branch | head -1 (or git status)
* develop
9) git checkout 545a36f
Note: checking out '545a36f'.
You are in 'detached HEAD' state.
10) git branch | head -1 (or git status)
* (HEAD detached at 545a36f)
11) git checkout origin/develop
12) git branch | head -1 (or git status)
* (HEAD detached at 545a36f)

As you can see, checking out a revision by SHA1 after checking out a local branch tells you you are detached at that SHA1. Ok. But, checking out a revision by SHA1 after checking out a remote tracking branch tells you you are detached at that remote tracking branch. And checking out a remote tracking branch after checking out a revision by SHA1 tells you you are detached at that SHA1.

This is confusing. Is this by design? For a script I am writing, it would be great if the output would be consistent. Checkout origin/develop should always say "detached at origin/develop". Checkout 545a36f should always say "detached at 545a36f".

It looks like the detached head information is only updated when a detached head state is entered and not anymore when a checkout occurs "within" a detached head state.
Best regards,
Stijn
Next: Michael J Gruber
Message 1 of 4 in “Branch information (git branch/status) inconsistent when in detached HEAD state”
  1. Stijn De RuyckOct 6, 2015
  2. Michael J GruberOct 7, 2015
  3. Stijn De RuyckOct 7, 2015
  4. Michael J GruberOct 7, 2015

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.