Reputation: 2535
I am trying to create a new branch under feature tag of my repo, I am using following to do this:
git branch "feature/BA-302-[AU]Intl-BCard"
However I am getting:
fatal: 'feature/BA-302-[AU]Intl-BCard' is not a valid branch name
Not sure, what I am missing. Also to clarify, I have already tried to:
git checkout -b feature/BA-302-[AU]Intl-BCard
With the following result:
zsh: no matches found: feature/BA-302-[AU]Intl-BCard
Upvotes: 24
Views: 53262
Reputation: 1329652
Not sure, what I am missing
That is exactly what Git 2.45 (Q2 2024), batch 8, addresses: when git refuses to create a branch because the proposed branch name is not a valid refname, an advice message is given to refer the user to exact naming rules.
See commit 8fbd903, commit 15cb037, commit 3ccc478, commit 95c987e, commit 8c5001c (05 Mar 2024) by Kristoffer Haugsbakk (LemmingAvalanche
).
(Merged by Junio C Hamano -- gitster
-- in commit b09a883, 15 Mar 2024)
branch
: advise about ref syntax rulesSigned-off-by: Kristoffer Haugsbakk
git-branch(1)
will error out if you give it a bad ref name.
But the user might not understand why or what part of the name is illegal.The user might know that there are some limitations based on the loose ref format (filenames), but there are also further rules for easier integration with shell-based tools, pathname expansion, and playing well with reference name expressions.
The man page for
git-check-ref-format(1)
contains these rules.
Let's advise about it since that is not a command that you just happen upon.
Also make this advise configurable since you might not want to be reminded every time you make a little typo.
git config
now includes in its man page:
refSyntax
Shown when the user provides an illegal ref name, to tell the user about the ref syntax documentation.
Upvotes: 2
Reputation: 242373
[
is not allowed in a branch name. See man-page for git-check-ref-format
or here for more details.
In zsh
, [...]
defines a character class the shell tries to match. If there's no match, you get the error zsh: no matches found
. Using quotes prevents the matching. In bash, similar behaviour can be turned on by running shopt -s failglob
.
Upvotes: 23
Reputation: 425
In my case it was a space. Branch name can't contain whitespace character.
Upvotes: 19