Re: [Bug] Porcelain allows creation of '@' branch
- From
D. Ben Knoble <ben.knoble@gmail.com>
- Date
- Aug 31, 2026, 19:59 UTC
- Message-ID
- <CALnO6CCph_xC394v_BetLPyoriYc9dLZY42LsXhjVNdvt2e-cQ@mail.gmail.com>
- In-Reply-To
- <4e8d8b75-ddf4-4602-a2a8-26e5214c65f0@arm.com>
On Mon, Aug 31, 2026 at 3:12 PM Bence Csókás <bence.csokas@arm.com> wrote:
Show 11 quoted lines
> > Hi, > > I ran into this issue a few weeks ago. I'm using Git 2.55.0, which is > the latest released. > > `git help check-ref-format` says this about a branch name: > > [...] > 9. They cannot be the single character @. > [...]
This is the rule for a reference.
Show 10 quoted lines
> And as expected, it is rejected: > > $ git check-ref-format @ && echo BUG! > $ > > However, the following commands all create a branch named @ : > > $ git checkout -b @ > $ git switch -c @ > $ git branch @
But (with git refs list) we should see this creates a ref "refs/heads/@".
I happen to think that's extremely confusing given that "@" is the shorthand for HEAD, but… it's not against the current documented rules, I think. (e.g., "git switch @" will fail, since it sees "git switch HEAD"; using "refs/heads/@" will also fail.) git-checkout doesn't fail but also doesn't change to the "@" branch. Futzing with .git/HEAD and restoring the working tree works, but… yikes.
Of course, --branch mode is allowed to be stricter; maybe we should reject this case?
Show 33 quoted lines
> I believe this to be a bug. Other invalid names are properly rejected
> though:
>
> $ git checkout -b master@{1}
> fatal: 'master@{1}' is not a valid branch name
> hint: See 'git help check-ref-format'
> hint: Disable this message with "git config set advice.refSyntax false"
> $ git checkout -b @{1}
> fatal: '@{1}' is not a valid branch name
> hint: See 'git help check-ref-format'
> hint: Disable this message with "git config set advice.refSyntax false"
> $ git checkout -b @^
> fatal: '@^' is not a valid branch name
> hint: See 'git help check-ref-format'
> hint: Disable this message with "git config set advice.refSyntax false"
>
> After creation, this branch cannot be checked out again, as `git
> checkout @` is a no-op. Luckily though, `git branch -d @` works, so I
> didn't permanently damage my Git repo :P
>
> Bence
>
> P.S. as I was typing this mail, I realized that I should've given
> `--branch` to check-ref-format, and sure enough, there's the problem:
>
> $ git check-ref-format --branch @
> @
> $ git check-ref-format --branch @{1}
> fatal: '@{1}' is not a valid branch name
> $
>
> Not sure why it thinks that would be a valid branch name...
> IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.(I don't recall offhand where we describe valid branch names, if at all.)
-- D. Ben Knoble