How to name branches and write commit messages when using git? A thorough summary of all usual conventions is given below.
Branch Naming Convention
Git branches can generally be separated into two categories:
Code Flow Branches
These branches which we expect to be permanently available on the repository follow the flow of code changes starting from development until the production.
Development
All new features and bug fixes should be brought to the development branch. Resolving developer codes conflicts should be done as early as here.Master
The production branch, if the repository is published, this is the default branch being presented.
Temporary Branches
Category
A temporary git branch should start with a category. Pick one of these: feature, bugfix, hotfix, or test.
feature
Any code changes for a new module or use case should be done on a feature branch. This branch is created based on the current development branch. When all changes are Done, a Pull Request/Merge Request is needed to put all of these to the development branch.bugfix
If the code changes made from the feature branch were rejected after a release, sprint or demo, any necessary fixes after that should be done on the bugfix branch.hotfix
If there is a need to fix a blocker, do a temporary patch, apply a critical framework or configuration change that should be handled immediately, it should be created as a Hotfix. It does not follow the scheduled integration of code and could be merged directly to the production branch, then on the development branch later.test
is for experimenting outside of an issue/ticket
Reference
After the category, there should be a “/“ followed by the reference of the issue/ticket you are working on. If there’s no reference, just add no-ref.
Description
After the reference, there should be another “/“ followed by a description which sums up the purpose of this specific branch. This description should be short and “kebab-cased”.
By default, you can use the title of the issue/ticket you are working on. Just replace any special character by “-“.
To sum up, follow this pattern when branching:
1 | git branch <category/reference/description-in-kebab-case> |
Examples
You need to add, refactor or remove a feature:
1 | feature/issue-42/create-new-button-component |
You need to fix a bug:
1 | bugfix/issue-342/button-overlap-form-on-mobile |
You need to fix a bug really fast (possibly with a temporary solution):
1 | hotfix/no-ref/registration-form-not-working |
You need to experiment outside of an issue/ticket:
1 | test/no-ref/refactor-components-with-atomic-design |
Commit Naming Convention
Commit Message Format
Each commit message consists of a header, a body and a footer. The header has a special format that includes a type, a scope and a subject:
1 | <type>[optional scope]: <subject> |
Type
Must be one of the following:
- feat for a new feature for the user, not a new feature for build script. Such commit will trigger a release bumping a MINOR version.
- fix for a bug fix for the user, not a fix to a build script. Such commit will trigger a release bumping a PATCH version.
- perf for performance improvements. Such commit will trigger a release bumping a PATCH version.
- docs for changes to the documentation.
- style for formatting changes, missing semicolons, etc.
- refactor for refactoring production code, e.g. renaming a variable.
- test for adding missing tests, refactoring tests; no production code change.
- build for updating build configuration, development tools or other changes irrelevant to the user.
- ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
- revert: reverts a previous commit. Begins with revert: , followed by the header of the reverted commit. In the body it should say: This reverts commit
., where the hash is the SHA of the commit being reverted. - chore: Update something without impacting the user (updating grunt tasks bump a dependency in package.json. no production code change).
Scope(optional)
Scope can be anything specifying place of the commit change.
- init
- runner
- watcher
- config
- web-server
- proxy
- etc.
Subject
The subject contains a succinct description of the change:
- use the imperative, present tense: “change” not “changed” nor “changes”
- don’t capitalize the first letter
- no dot (.) at the end
Body(optional)
Just as in the subject, use the imperative, present tense: “change” not “changed” nor “changes”. The body should include the motivation for the change and contrast this with previous behavior.
Footer(optional)
The footer should contain any information about Breaking Changes and is also the place to reference GitHub issues that this commit Closes.
Breaking changes
Breaking Changes should start with the word BREAKING CHANGE: with a space or two newlines. The rest of the commit message is then the description of the change, justification and migration notes.
BREAKING CHANGE example with two newlines
1 | BREAKING CHANGE: |
BREAKING CHANGE example with a space
1 | BREAKING CHANGE: isolate scope bindings definition has changed and |
Any commit with the breaking change section will trigger a MAJOR release and appear on the changelog independently of the commit type.
Referencing issues
Closed bugs should be listed on a separate line in the footer prefixed with “Closes” keyword like this:
1 | Closes #234 |
or in case of multiple issues:
1 | Closes #123, #245, #992 |
Commit Message Examples
Standard commit message
1 | fix(middleware): ensure Range headers adhere more closely to RFC 2616 |
Commit message with no body
1 | docs: correct spelling of CHANGELOG |
Commit message with scope
1 | feat(lang): add Polish language |
Commit message with body and footer
1 | feat($browser): onUrlChange event (popstate/hashchange/polling) |
Commit message with multi-paragraph body and multiple footers
1 | fix: prevent racing of requests |
Commit message with body and footer of referencing issue
1 | fix($compile): couple of unit tests for IE9 |
Commit message with multi-paragraph body and footer of BREAKING CHANGE
1 | feat($compile): simplify isolate scope bindings |
References
- A Simplified Convention for Naming Branches and Commits in Git
https://dev.to/varbsan/a-simplified-convention-for-naming-branches-and-commits-in-git-il4 - Git Branch Naming Convention
https://dev.to/couchcamote/git-branching-name-convention-cch - Git Commit Msg
https://karma-runner.github.io/6.3/dev/git-commit-msg.html - Conventional Commits 1.0.0
https://www.conventionalcommits.org/en/v1.0.0/#summary - Contributing to Angular
https://github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#-commit-message-guidelines - AngularJS Git Commit Message Conventions
https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit