Write Better Git Commit Messages with Conventional Commits

3/21/2022

Probably most developers know the struggle of writing good and consistent git commit messages. If you have the same problem you should take a look at the Conventional Commits specification.

I've been writing commits according to this specification (with some additions) for a while now and the commit history of all projects became a lot more consistent and easier to understand.

The basic structure of a „conventional commit message“ is

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

with the following parts:

DescriptionExamples
typethe commit type„feat“, „fix“, „chore“, …
scope (optional)a scope to group commits for a specific topicname of a feature, „api“, „auth“, …
descriptiona short, lowercase description of the commit in present tense„add readme file“

Commit Types

Although the Conventional Commits specification only explicitly includes the feat and fix types, the documentation says that other types are allowed. There are a few variants of allowed types. Here are the ones I use:

TypeDescriptionExample Commit
feata new feature or enhancement to the codebasefeat(api): add system status endpoint
fixpatch for a bugfix(auth): unhandled exception for duplicate usernames
bumpversion updatebump: version 1.0.2
cicontinuous integration changesci: add unit tests to workflow
docschanges to the documentationdocs: create readme
localizelocalization/translation updateslocalize(login): add German translation for login btn
perfperformance improvementsperf(search): improve sql query
refactorrefactoring, improved code with the same functionalityrefactor: move duplicate methods to shared parent class
stylecode style changesstyle: correct indentation
testadding or updating teststest(auth): add jwt module unit test
contentnew or updated content (e.g. for a git-based CMS)content(blog): add conventional commits article
choreanything else (like dependency updates, db dumps, ...)chore(composer): update dependencies

For more information and the full specification please visit the conventionalcommits.org website!