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

[Bug] incomplete defence agains creating a branch named HEAD

From
Dennis Kaarsemaker <dennis@kaarsemaker.net>
Date
Aug 5, 2015, 15:46 UTC
Message-ID
<1438789577.17587.7.camel@kaarsemaker.net>
So git branch doesn't like to create a branch named HEAD

$ git branch HEAD fatal: it does not make sense to create 'HEAD' manually

But, you can trick it into doing so anyway:
$ git branch @
$ git branch -a
  HEAD
* master
At which point git status becomes a bit confused:

$ git status warning: refname 'HEAD' is ambiguous. warning: refname 'HEAD' is ambiguous. On branch master nothing to commit, working directory clean

Oh, and git checkout will accept either HEAD or @ to create a branch with the name HEAD anyway:

$ git checkout -b HEAD Switched to a new branch 'HEAD'

$ git checkout -b @ Switched to a new branch 'HEAD'

imho none of these should create a branch named HEAD, but should do what 'git branch HEAD' does and fail with a sensible error message.

All these shenanigans came up when trying to help an user who is mirroring a mercurial repo that has a branch named '@'. Whether or not git should allow branches named '@' I don't have an opinion on, I know '@' is pretty special when dealing with refs.

-- 
Dennis Kaarsemaker
www.kaarsemaker.net
Message 1 of 1 in “[Bug] incomplete defence agains creating a branch named HEAD”
  1. Dennis KaarsemakerAug 5, 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.