Data report"State of code review 2024" is now liveRead the full report

Best practices for naming Git branches

Greg Foster
Greg Foster
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Branch naming conventions in Git provide a systematic way to organize and reference branches within a repository. These conventions are not enforced by Git itself but can be implemented through team policies or automated scripts. Effective branch naming is essential for clarity, especially in projects with multiple contributors.

Git imposes some basic restrictions on branch names:

  • Characters: Branch names can include letters, numbers, dashes (-), underscores (_), and dots (.), but they cannot begin with a dot or end with a slash (/).
  • Case sensitivity: Git is case-sensitive, so Feature and feature are considered different branches.
  • Reserved names: Names like HEAD, FETCH_HEAD, ORIG_HEAD, and others are reserved by Git and cannot be used as branch names.
  • Length: While there's no strict limit on the length of branch names, it's practical to keep them concise to make them easier to manage.
Stop wrestling with Git commands

The Graphite CLI takes all the pain out of Git, allowing you to ship faster and stop Googling Git commands.

Learn more

Using prefixes in branch names is a popular strategy to categorize branches based on their purpose:

  • Feature branches: Prefixed with feature/, these branches are used to develop new features.
  • Bugfix branches: Prefixed with bugfix/, these branches are used to make fixes.
  • Release branches: Prefixed with release/, these branches prepare a codebase for new releases.
  • Hotfix branches: Prefixed with hotfix/, these branches address urgent issues in production.

Git Flow is a branching model that outlines a strict branching strategy designed for managing releases. The main branches in Git Flow include:

  • Main branch: Serves as the primary branch where the codebase's current production state is reflected.
  • Develop branch: Aggregates developments and features before they are released to the main branch.
  • Feature branches: Typically follow the naming pattern feature/*, these branches are used to develop new features.
  • Release branches: Named like release/*, these branches help manage the release process.
  • Hotfix branches: Named hotfix/*, these branches are created to quickly patch production releases.

The Graphite CLI automatically names your branches for you upon creation, ensuring consistency in following best naming conventions.

The Graphite CLI simplifies git, handles rebasing automatically, and allows you to create, submit, and stack pull requests right from the command line.

Under the hood, the CLI runs Git to create branches, commits, and metadata, which means you can still use Git in your scripts, tooling, or whenever you feel like it. Read more about installing the Graphite CLI in our docs.

screenshot of the Graphite CLI

For larger teams using product management software to track ticket numbers, it's crucial to adopt a clear and standardized Git branch naming convention to maintain organization and facilitate collaboration.

  1. Prefix with ticket number: Start the branch name with the ticket number associated with the task or issue being addressed. This ensures that branches are easily identifiable and linked to specific tickets in the project management system.

  2. Use hyphens for readability: Separate the ticket number from the branch description using hyphens for readability. This helps team members quickly understand the purpose of the branch without having to inspect its contents.

  3. Use descriptive branch names: After the ticket number, provide a brief but descriptive name for the branch that summarizes the changes being made. This can include keywords related to the feature, bug fix, or enhancement being implemented.

  4. Limit length: Keep branch names concise to avoid excessive verbosity. While it's essential to provide enough information for clarity, overly long branch names can become cumbersome and difficult to manage.

  5. Lowercase and dashes: Stick to lowercase letters and use dashes instead of spaces in branch names to ensure compatibility across different operating systems and Git hosting platforms.

For example you can name your branches similar to:

Terminal
feature/PROJ-123-add-user-authentication

In this example:

  • feature indicates that it's a feature branch.
  • proj-123 is the ticket number associated with the task.
  • add-user-authentication provides a clear description of the changes being made.

By following this convention, teams can easily track the progress of individual tasks, understand the purpose of each branch, and seamlessly integrate their work using Git within the context of their product management workflow.

The best engineers use Graphite to simplify Git

Engineers at Vercel, Snowflake & The Browser Company are shipping faster and staying unblocked with Graphite.

Git started for free

Choosing good branch names is crucial for maintaining an organized repository. Good branch names are usually:

  • Descriptive: Names should reflect the branch's purpose or task.
  • Concise: Keep names short and to the point.
  • Consistent: Follow established patterns to make it easy for team members to understand the role of each branch.

Here's a hypothetical example of how branch naming would appear in a terminal:

Terminal
# Creating a new feature branch
git checkout -b feature/add-user-authentication
# Switching to a bugfix branch
git checkout -b bugfix/login-issue
# Creating new release branch
git checkout -b release/v2.0.0
# Preparing a hotfix
git checkout -b hotfix/reset-password-fix

In each command, git checkout -b is used to create and switch to a new branch, with the branch name immediately following the command indicating its purpose and structure.

Adhering to a clear set of branch naming conventions can greatly enhance the manageability of a software project. Whether you're using plain Git, GitLab, or adopting the Git Flow approach, consistent and meaningful branch names streamline the development process and enhance collaboration. By understanding and implementing these conventions, teams can ensure a more organized and efficient workflow.

For further reading on git branch naming conventions see the official Git documentation.

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2