When working on a project tracked with git, you will sure do create branches. You have the main
branch of course, but then a good practice is also to have one branch per features you are developing. Below what it might look like at then end:
> git branch
* master
dev/JIRA-1234
dev/JIRA-5487_add_users_filtering
dev/add_google_sign_in_authentication_form
dev/ISSUE-987
Let’s have a closer look on how to name them (even though the above snippet already gives you a hint).
Main branch
The main
or master
branch is treated as the unique source of truth, the official working code base. This is a place where everything must be working. It is the default branch you come up with when you initialize a new git project.
Notes:
- Since 2020 and 2022, Github and Gitlab (respectively) renamed their default branch from
master
tomain
to avoid language that might be seen as offensive. - If you do not want to politicize git and still prefer the old naming convention, you can still rename
main
formaster
manually. How to rename git branch explains how to do it.
Feature branches
It is time to add features into our main
branch. Since main
is the place where everything must be working, you first want to test your changes on a development branch. Usually, you end up with 1 branch per feature. Each of them templated as follow:
dev/JIRA-1234
dev/JIRA-1234_add_users_filtering
dev/add_google_sign_in_authentication_form
dev/ISSUE-987
In a nutshell, the following rules apply:
- Prefix the non-main branch with
dev/
. It will makes easier to trigger the dedicated Gitlab CI jobs via branches filtering. - If you use an issue tracker like Jira, include the ticket’s ID. Gitlab includes a Jira Integration facility tool e.g. creating links to the Jira ticket on the fly.
- Beside the ticket ID, stick to the good old snake_case. See also Why you should use Snake Case.
- If you do not use an issue tracker e.g. for personal projects, simply describe the feature you are implementing.