Skip to content

Instantly share code, notes, and snippets.

@jefffederman
Last active February 12, 2024 08:39
Show Gist options
  • Save jefffederman/1d492f98b8e3913a75ca to your computer and use it in GitHub Desktop.
Save jefffederman/1d492f98b8e3913a75ca to your computer and use it in GitHub Desktop.
Naming `git` branches

Naming git branches

tldr; {type}/{group[optional]}/short-form-of-what-it-does

HCM developers consistently use dash-delimited branch names. About half also use f/ and b/ prefixes ('feature' and 'bug', respectively).

I suggest we continue our current practices, specifically:

  • a branch should start with a prefix indicating its type: feature/, bug/, chore/, or hotfix/

    • prefer the whole word to the one letter abbreviation, the clarity outweighs the cost of the extra characters
    • feature, bug and chore cover most of what we'd need; feel free to use hotfix/ for branches consisting of multiple urgent bug fixes
  • a branch should contain an optional group/team if it makes sense, e.g., onboarding, pto, esig

    • the group should be something meaningful on its face, e.g., not gobstopper

Slash delimiters in branch names can be a divisive topic, but I believe the pros outweigh the cons.

Pros:

  • can use git pattern matching, e.g., git branch --list "feature/*"
  • has the benefit of prompting some git GUI-based tools to allow collapsing token divisions like a directory list view

Cons:

  • cannot have a branch name consisting entirely of one of our prefixes, i.e., "feature", "bug", "chore" or "hotfix"
  • some people find the similarity to path names confusing

Some other branch naming tips:

Do not use use bare numbers (or hex numbers) as part of your branch naming scheme. Inside tab-expansion of a reference name, git may decide that a number is part of a sha-1 instead of a branch name.

E.g., If you tried to expand just 15032, git would be unsure whether you wanted to search SHA-1's or branch names, and your choices would be somewhat limited.

See:

http://mirocommunity.readthedocs.org/en/latest/internals/branching-model.html http://stackoverflow.com/questions/273695/git-branch-naming-best-practices

@SeanCoaker
Copy link

Hi. I know this is kind of not very new, but I do have a question about this. Maybe someone will answer.

a branch should start with a prefix indicating its type

Why? What difference does it make, if the branch is prefixed?

It's a preference thing. I myself prefer to see what the changes in the branch are trying to do, and prefixing the branch name can help you to identify this without needing any other info. It then helps when coming to PRs and code reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment