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

Confusing error message for git switch -d

From
Anselm Schüler <mail@anselmschueler.com>
Date
Sep 25, 2024, 22:25 UTC
Message-ID
<ce9f0440-e724-4116-b63a-0e62c46c170d@anselmschueler.com>
Hi,

I just ran into a confusing error message when using git switch -d, specifically in a clone of the CPython code repository.

I wanted to get the code for CPython 3.12, so I tried running git switch -d 3.12, expecting 3.12 to be a tag (which it wasn’t, and it was a remote branch).

Git produced this error message:
fatal: '--detach' cannot be used with '-b/-B/--orphan'
This is confusing since I didn’t pass any of these options.

I believe I have determined that this error message occurs when using git switch -d to switch to a remote branch that hasn’t yet had a local branch that tracks it created for it.

Why is Git producing this error specifically? It also seems that, whatever the reason, a user probably doesn’t know, so a better error message might be a good idea.

To clarify, if I’d known that my assumption of it being a tag was wrong, I’d’ve still expected Git to act differently, specifically, it could’ve switched to the commit the branch is pointing to in detached HEAD mode (as it does when using -d with other branches).

Thanks Anselm

PS: Are there no mailing list servers that support HTML messages? Why 
are they not allowed, even with plaintext fallback?
Next: Junio C Hamano
Message 1 of 2 in “Confusing error message for git switch -d”
  1. Anselm SchülerSep 25, 2024
  2. Junio C HamanoSep 25, 2024

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.