Git Branch Naming Conventions
Overview
Git branch naming conventions are the set of rules which are followed by the developers while creating and naming any branch. This naming convention helps the developer to get an overview of what is the purpose of the particular branch without getting into the code inside that branch.
Categories of Git Branches
Git branches are broadly classified into two categories :
- Regular Git branches
- Temporary git branches
Regular Git Branches
Regular Git branches are those branches that are permanently available in your repositories. These can be further classified into three categories namely Dev branch, master branch, and QA branch or test branch.
- Dev branch is the development branch that is used by developers to develop any new feature. The developers can not directly write code in the master branch as the master branch is the production branch. When the code in the dev branch undergoes reviews and testing then only it is merged into the master branch.
- Master branch is the default branch in the Git repository. The master branch is the life of the production branch which is deployed to production. The Master branch should be stable every time and before any merging, any code from the dev branch to the master branch must undergo rigorous testing and verification.
- QA branch or the test ranch is used for QA testing and automation testing before merging any code to production.
Temporary Git Branches
Temporary Git branches are the branches that are created and deleted as per requirement. They are not present permanently in the repository.
They can be classified into the following branches
- Bug Fix
- Hot Fix
- Feature Branches
- Experimental Branches
- WIP branches
Git Branching Naming Convention
Some naming conventions generally followed by developers are :
Start Branch Name with Group Word
The branch name should start with a group word that signifies the purpose of the branch.
Some group words used are Bug, Hotfix, or WIP(work in progress) which makes all the developers get an idea of what the branch is meant for.
Some examples of such Git branch names are :
bug-header-size-issue - The developer is trying to fix the header-size bug. WIP-login-feature - The developer is trying to implement the login functionality which is in progress.
Use Unique ID Nn Branch Names
Some companies use Jira for creating tickets for issues and new features to be developed. This ticket has a ticket number and is assigned to developers to complete.
We can use these ticket numbers in Git branch naming which helps in tracking the progress of the work in that branch.
For example, WIP-532-add-to-cart-feature - The developer is working on ticket number 532 which is add-to-cart functionality and is currently in progress.
Use Hyphen or Slash as Separators
Developers use a hyphen(-) or slash(/) while naming the Git branches. Which one to use Hyphen or slash completely depends on the team.
If you are using hyphens then only hyphens should be used by every team member for consistency.
The hyphen helps in name readability and also avoids confusion while reading the branch name. It becomes easy to manage branches when there are many branches in the repository.
For example,
feature checkout - when no hyphen or slash is used in naming the Git branch.
feature-checkout - when a hyphen is used while naming the branch. The readability of the branch increases.
Git Branch with Author Name
Many companies use the author name while naming any Git branch so that it is known which developer has worked on which branch.
For example,
rohan.singh-feature-checkout - Implies that rohan singh has worked on this checkout feature branch.
Avoid Using Numbers Only
Some developers only use the unique numbers while naming any new branch which leads to confusion with that magic number and also can create problems while merging that branch to master.
For example,
Bug-267- Do not imply what the branch is meant for. Bug-267-icon-alignment-issue - Implies that the branch with number 267 is for fixing the alignment issues.
Avoid Using All Naming Conventions Simultaneously
All the rules should not be used to name a branch every time. The team of developers should decide a particular way that will be followed by every developer in the team. In this way, the naming will be consistent.
Avoid Long Descriptive Names for Long-Lived Branches
The main intention of the naming convention of the branches is to provide brief information on what that branch is doing.
The branch name should not be precise and should be very long and the usage of unnecessary words should be avoided.
For example,
WIP-login-module-which-will-be-used-for-public-login - Unnecessary use of words makes the branch name longer and the context is not clear.
WIP-login-feature - A precise and understandable branch name.
Conclusion
- Git branch naming conventions are the set of rules which are followed by the developers while creating and naming any branch.
- Regular branches are permanent branches in the repository.
- Temporary branches are created and deleted as per use.
- Git branch should specify the use case or work for which that branch is created.
- Start any branch name with a group word like a bug, hotfix, feature, etc.