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
You should never name a tag and a branch the same name! It makes sense in a case like this to use naming conventions on the tags to keep from colliding on the branch names. Versus when we releasing code from the master branch. You can find the common parent in git using merge-base to do a Tag on code from the past.
In order to compare two branches easily, you have to use the “git diff” command and provide the branch names separated by dots. Using this command, Git will compare the tip of both branches (also called the HEAD) and display a “diff” recap that you can use to see modifications.
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:
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 /. 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.
They cannot have two consecutive dots .. anywhere.
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.
They cannot begin or end with a slash / or contain multiple consecutive slashes (see the --normalize option below for an exception to this rule)
They cannot end with a dot ..
They cannot contain a sequence @{.
They cannot be the single character @.
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>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With