Branch Naming Convertion
When working in a team, a consistent Git branch naming convention provides clarity about the work done in a specific branch. It also makes it easier to locate a particular branch in a repository. Below we delve into some best practices when it comes to Git branch naming conventions. Use this as a cheat sheet for your daily Git use, and you’ll see your workflow efficiency skyrocket.
Basic Rules
- Lowercase and Hyphen-separated: Stick to lowercase for branch names and use hyphens to separate words. For instance,
feature/new-loginorbugfix/header-styling. - Alphanumeric Characters: Use only alphanumeric characters (a-z, A-Z, 0–9) and hyphens. Avoid punctuation, spaces, underscores, or any non-alphanumeric character.
- No Continuous Hyphens: Do not use continuous hyphens.
feature--new-logincan be confusing and hard to read. - No Trailing Hyphens: Do not end your branch name with a hyphen. For example,
feature-new-login-is not a good practice. - Descriptive: The name should be descriptive and concise, ideally reflecting the work done on the branch.
Branch Prefixes
Using prefixes in branch names helps to quickly identify the purpose of the branches. Here are some common types of branches with their corresponding prefixes:
- Feature Branches: These branches are used for developing new features. Use the prefix
feature/. For instance,feature/login-system. - Bugfix Branches: These branches are used to fix bugs in the code. Use the prefix
bugfix/. For example,bugfix/header-styling. - Hotfix Branches: These branches are made directly from the production branch to fix critical bugs in the production environment. Use the prefix
hotfix/. For instance,hotfix/critical-security-issue. - Release Branches: These branches are used to prepare for a new production release. They allow for last-minute dotting of i’s and crossing t’s. Use the prefix
release/. For example,release/v1.0.1. - Documentation Branches: These branches are used to write, update, or fix documentation (e.g., the
README.mdfile). Use the prefixdocs/. For instance,docs/api-endpoints.
Including Teams (or other Project Management Tool) Ticket Numbers
In some workflows, especially in larger teams, it’s common to include the ticket number from a project management tool like Jira in the branch name. This makes it easy to track the work done on a specific ticket. For instance, if you are working on a ticket numbered “T-123” for adding a new login system, the branch name could be feature/T-123-new-login-system.
We need to discuss as a team which "ticket numbers" we can use for the workflow.
Sample Branch Names
Here are some samples of good branch names following the above conventions:
feature/user-authenticationbugfix/fix-header-stylinghotfix/security-patchrelease/v2.0.1docs/update-readme
Or with ticket no:
feature/T-456-user-authenticationbugfix/T-789-fix-header-stylinghotfix/T-321-security-patchrelease/v2.0.1docs/T-654-update-readme