Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not a valid git branch name

Tags:

git

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

like image 824
User3 Avatar asked Jun 15 '19 16:06

User3


People also ask

Can a branch name have '/' in git?

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

How do I create a new branch in git?

New Branches The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.

How long can a git branch name be?

So, this is how we reached the Git branch name character limitation of 28 characters.


2 Answers

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

like image 52
Ingo Kodba Avatar answered Nov 02 '22 08:11

Ingo Kodba


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

like image 18
choroba Avatar answered Nov 02 '22 07:11

choroba