Name branches like commits
I name a branch the same way I name the commit. The prefix is a Conventional Commits type. If you have an issue id, put it in the name. If you don't, skip it.
feat/123-add-new-residence-pagefeat is the type. 123 is the issue id. add-new-residence-page is the description. That name is 31 characters.
Prefix
The prefix is the type you will put on the commit. Conventional Commits requires feat for a new feature and fix for a bug fix. Other types are allowed. I use the types from commitlint's conventional config:
feat, a new featurefix, a bug fixdocs, documentation onlystyle, formatting that does not change what the code doesrefactor, a code change that is not a fix and not a featureperf, a code change that makes the code fastertest, new tests, or a correction to existing testsbuild, the build system or dependenciesci, CI config and scriptschore, a change that does not touchsrcor test filesrevert, a revert of an earlier commit
Use the short type from that list. A new feature is feat. A bug fix is fix. A hotfix is fix.
Issue id
If you have an issue id, put it right after the prefix.
feat/123-add-new-residence-page
fix/456-login-validation
refactor/789-migrate-to-next-14If you don't have an issue id, skip it.
feat/add-new-residence-page
fix/login-validation
refactor/migrate-to-next-14The description does not repeat the type. The prefix already says fix.
Description
The description is lowercase. A hyphen splits the words. The words state the change.
refactor/789-migrate-to-next-14Length
Keep the branch name at 50 characters or fewer.
With an issue id:
feat/123-add-new-residence-pageis 31 characters.fix/456-login-validationis 24 characters.refactor/789-migrate-to-next-14is 31 characters.
With no issue id:
feat/add-new-residence-pageis 27 characters.fix/login-validationis 20 characters.refactor/migrate-to-next-14is 27 characters.
Set the name
- Pick the commit type.
- If you have an issue id, put it after the type.
- If you don't have an issue id, skip it.
- Write a short description in lowercase, with a hyphen between the words.
- If the name is longer than 50 characters, cut words from the description.
- Use this pattern on every branch.
Takeaway
The branch and the commit share one type. Put the issue id in the name when you have one. Skip it when you don't.
References
- Conventional Commits - conventionalcommits.org/en/v1.0.0
- commitlint - github.com/conventional-changelog/commitlint