6

When I name branches in Git, I always tend to start with a letter. mybranch89 for example.

Are there any rules to naming Git branches? For example, should I always begin with a letter, or are number only branch names possible such as 876

henrywright
  • 10,070
  • 23
  • 89
  • 150

1 Answers1

12

The rules are rather complicated, but when you consider that branches end up as files on the filesystem, they make sense:

Git imposes the following rules on how references are named:

  1. They can include slash / for hierarchical (directory) grouping, but no slash-separated component can begin with a dot . or end with the sequence .lock.

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

  3. They cannot have two consecutive dots .. anywhere.

  4. They cannot have ASCII control characters (i.e. bytes whose values are lower than \040, or \177 DEL), space, tilde ~, caret ^, or colon : anywhere.

  5. They cannot have question-mark ?, asterisk *, or open bracket [ anywhere. See the --refspec-pattern option below for an exception to this rule.

  6. They cannot begin or end with a slash / or contain multiple consecutive slashes (see the --normalize option below for an exception to this rule)

  7. They cannot end with a dot ..

  8. They cannot contain a sequence @{.

  9. They cannot be the single character @.

  10. They cannot contain a \.

Note that this is for naming of references, not branches. A branch is a reference that looks like refs/heads/<branchname>.

Thomas
  • 174,939
  • 50
  • 355
  • 478