24

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 
6
  • are you trying to create new branch ? Commented Jun 15, 2019 at 16:58
  • git checkout -b feature/BA-302-[AU]Intl-BCard Commented Jun 15, 2019 at 16:58
  • Yes I am trying to create a new branch with my current changes Commented Jun 15, 2019 at 16:59
  • Run command git checkout -b feature/BA-302-[AU]Intl-BCard then git push -u origin feature/BA-302-[AU]Intl-BCard Commented Jun 15, 2019 at 17:01
  • 1
    See man git-check-ref-format for valid ref names. Commented Jun 15, 2019 at 17:04

3 Answers 3

24

[ 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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this works for me - was scratching my head off! :D
21

In my case it was a space. Branch name can't contain whitespace character.

1 Comment

Thank you! I replaced all spaces with underscores _ and the branch created perfectly.
2

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 rules

Signed-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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.