Search code examples
gitbranchzshgit-branchconventions

Can i use "[ ]" on git branch?


I like to use branch like [#3]feature: filter [#issue num]type: title

But terminer shows me "zsh: no matches found: [#3]feature:filter"

Can't i use "[ ]" on branch names?


Solution

  • Git has a command git check-ref-format to check if a ref name is valid. As the doc says, [ is not valid. And in your case, a space and a colon are also invalid.

    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.

    You can test a branch by git check-ref-format --branch '<branchname>'.

    git check-ref-format --branch '[#3]feature:filter'
    fatal: '[#3]feature:filter' is not a valid branch name