命名 Git 个分支时的规则

Rules when naming Git branches

当我在 Git 中命名分支时,我总是倾向于以字母开头。 mybranch89 例如。

Git 分支的命名有什么规则吗?例如,我应该始终以字母开头,还是只有数字可以作为分支名称,例如 876

规则是 rather complicated,但是当您考虑分支最终作为文件系统上的文件时,它们是有道理的:

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 0, or 7 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 \.

请注意,这是为了 引用 的命名,而不是分支。分支是类似于 refs/heads/<branchname>.

的引用