Git Branch Naming Best Practices

Naming your git branches is important for smooth team collaboration and project management.

Here are a few straightforward tips to enhance your git branch naming game.

Begin with a Purpose

Start your branch name with a keyword that signifies the branch's purpose. Common keywords include:

  • feature: For new features or updates
  • bugfix: For bug fixes.
  • hotfix: For temporary critical fixes

I've often seen wip, test, and other variations but I find sticking to feature and bugfix is usually verbose enough for most codebases.

Pick a Separator

Use a dash (-) or slash (/) to make your branch names more readable. Consistency with your choice of separator across all branch names enhances clarity. Another option is to mix them. Here are a few examples:

  • refactor-login-flow
  • refactor/login/flow
  • refactor/login-flow

Incorporate Issue ID

Include the ID of the associated issue in the branch name for easy reference and tracking.

Example: feature-123-new-login-button

Avoid naming branches with only numbers. It's vague and prone to confusion, so mix issue IDs with descriptive words for clarity.

Keep It Short and Simple

While informative, branch names should also be brief to avoid complexity and ensure ease of use. This can often be tricky since naming is one of the hardest things in coding. But once you get used to it, you'll find a way.


Once you decide on a naming strategy, consistency is key.

Stick to your conventions throughout the project's lifespan. Future you will thank you! Add it to your CONTRIBUTING.md so new contributors can also figure it out easily.

GitGithub
Avatar for Niall Maher

Written by Niall Maher

Founder of Codú - The web developer community! I've worked in nearly every corner of technology businesses: Lead Developer, Software Architect, Product Manager, CTO, and now happily a Founder.

Loading

Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.