Git offers flexible branching strategies, but what does it mean? In simple words, a branching strategy is a set of rules, a convention that helps teams and developers – they can follow these rules and conventions to create a new branch, its flow, etc.
Not using appropriate naming conventions leads to confusion and complicates the code maintenance team. We can’t ignore Git best practices in branching naming conventions.
Git branching strategies allow separation of work. Broadly, we can divide Git branches into two categories: Regular & Temporary Branches.
These branches will be available in your repository on permanent bases. Their naming convention is simple and straightforward.
As the name indicates, these are the branches that can be created and deleted when needed. They can be as follows:
There are many formats and naming conventions recommended by experts for temporary branches.
Here is a simple workflow of Git branches.
In this article, I’ll review and share the seven best naming conventions which I used personally in the past to ensure their efficiency.
It is one of the best practices. The group word can be anything to match your workflow.
I like short words like the following:
By looking at the branch name, you can understand what this Git branch is about and its purpose.
Have a look at the below examples:
You can use the issue tracker Id in your branch name. I prefer this method when I work on fixing some bugs. For instance:
The name shows that the branch applies to the task of adding a testing module, the tracking Id of the issue is 8712, and the work is in progress.
One more advantage of using an external tracking ID in the branch name is the possibility to track the progress from an external system.
Many developers use slash as a separator, and many use hyphens. Which one to use – depends on you and your team’s preferences.
My opinion is that hyphens make the name more comfortable to read, so it’s a suitable separator in branch names. You can use slashes, hyphens, and underscores. The point is to be consistent.
There are two main advantages of using a separator in the branch name:
Example 1. Git branch name without any separator:
Example 2. By adding a separator (in this case, it is an underscore), you make the Git branch name readable:
Many companies prefer to add authors’ names into the branch names according to the format below:
This method allows for easy tracking of different developers’ work and progress with additional systems.
Some developers only use the issue Id in the branch name, which is not helpful in the work progress.
For instance, there is a branch name 9912 – what should this magic number tell us? It only means more confusion and risk of mistakes, especially during merging with other git branches.
Mixing and matching all Git branch naming conventions are not the best practice. It only adds confusion and complicates the overall processes.
A team should decide the naming conventions to use in work once, and stick to them. Consistency is the most critical thing.
The essential quality of a branch name is that it should be precise and informative. Let’s have a look at some examples again:
There, the branch names are long and detailed. It is not necessary. Instead, you might use the following variant:
This name is short, but it explains the purpose of this branch.
The Git branching model is powerful, but you need to manage the branches correctly and effectively. One of the necessary factors is following the same conventions by all teams, particularly – the naming conventions for the local repository.
To make sure your team is using the agreed conventions, enforce the standards. One of the easiest ways is to use Git hooks, like the pre-commit hook. I hope it will give you an idea about the Git branching models and their naming convention.
For more information, you can read my complete guide on Git Branching Naming Convention.
Alibaba Clouder - July 18, 2018
Alibaba Clouder - February 3, 2021
Alibaba Developer - December 2, 2021
Alibaba Clouder - July 24, 2019
gangz - December 10, 2020
Alex - October 16, 2018
A risk management solution that features real-time analysis and accurate identification and is suitable for all business scenarios.Learn More
A low-code development platform to make work easierLearn More
Help enterprises build high-quality, stable mobile appsLearn More
Alibaba Cloud (in partnership with Whale Cloud) helps telcos build an all-in-one telecommunication and digital lifestyle platform based on DingTalk.Learn More
More Posts by Hiteshjethva