Branch Names

The name you assign to a branch is essentially arbitrary, though there are some limitations. The default branch in a repository is named master, and most developers keep the repository’s most robust and dependable line of development on that branch. There is nothing magical about the name master except that Git introduces it during the initialization of a repository. If you prefer, you can rename or even delete the master branch, although it’s probably best practice to leave it alone.

To support scalability and categorical organization, you can create a hierarchical branch name that resembles a Unix pathname. For example, suppose you are part of a development team that fixes multitudes of bugs. It may be useful to place the development of each repair in a hierarchical structure under the branch name bug, on separate branches named something like bug/pr-1023 and bug/pr-17. If you find you have many branches or are just terminally over-organized, you can use this slash syntax to introduce some structure to your branch names.

Tip

One reason to use hierarchical branch names is that Git, just like the Unix shell, supports wildcards. For instance, given the naming scheme bug/pr-1023 and bug/pr-17, you can select all bug branches at once with a clever and familiar shorthand.

git show-branch 'bug/*'

Dos and Don’ts in Branch Names

Branch names must conform to a few simple rules:

  • You can use the forward slash (/) to create a hierarchical name scheme. However, the name cannot end with a slash.

  • No slash-separated component can begin with a dot (.). A branch name such as feature/.new is invalid

  • The name cannot contain two consecutive dots (..) anywhere.

  • Further, the name cannot contain:

    • Any space or other whitespace character

    • A character that has special meaning to Git, including the tilde (~), caret (^), colon (:), question-mark (?), asterisk (*), and open bracket ([)

    • An ASCII control character, which is any byte with a value lower than 40 octal, or the DEL character (177 octal)

These branch name rules are enforced by the git check-ref-format plumbing command, and they are designed to ensure that each branch name is both easily typed and usable as a filename within the .git directory and scripts.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.214.146