A short answer to your question is: unfortunately, this is not a legal branch name.
The article you referenced is incorrect (likely, simply because it is outdated). The rules for legal reference and branch names can be found in man 1 git-check-ref-format
:
Git imposes the following rules on how references are named:
They can include slash /
for hierarchical (directory) grouping, but no slash-separated component can begin with a dot .
or end with the sequence .lock
.
They must contain at least one /
. This enforces the presence of a category like heads/
, tags/
etc. but the actual names are not restricted. If the --allow-onelevel
option is used, this rule is waived.
They cannot have two consecutive dots .
. anywhere.
They cannot have ASCII control characters (i.e. bytes whose values are lower than \040, or \177 DEL
), space, tilde ~
, caret ^
, or colon :
anywhere.
They cannot have question-mark ?
, asterisk *
, or open bracket [
anywhere. See the --refspec-pattern
option below for an exception to this rule.
They cannot begin or end with a slash /
or contain multiple consecutive slashes (see the --normalize
option below for an exception to this rule)
They cannot end with a dot .
.
They cannot contain a sequence @{
.
They cannot be the single character @
.
They cannot contain a \
.
Note that these are the rules for references. There is a more strict set of rules for branches, they don’t seem to be listed in the manual, but it mentions that:
a dash may appear at the beginning of a ref component, but it is explicitly forbidden at the beginning of a branch name
which is exactly your case. In other words foo/bar/-test
is valid, while -test
is not.
Finally, you can sort of cheat by creating a branch with some other name, then going to .git/refs/heads
and renaming it in there (with mv
). You’ll then have this branch, you’ll be able to see it in git branch
(unlike branches, whose names are illegal for a reference), but you still won’t be able to checkout it.