Git and GitHub · Part 4 · Team workflows

Conventional commits

Messages machines can read

Compare two histories of the same week:

Without a convention
a1f3c2e updates
9b2d4e1 fixed it
7c8e0f3 new stuff for login
With Conventional Commits
a1f3c2e chore: update next to 16.1
9b2d4e1 fix(cart): keep the total after removing an item
7c8e0f3 feat(auth): add sign-in with GitHub

The second one says at a glance what kind of change each commit is. Because the format is fixed, tools can read it too: to write release notes, or to work out the next version number. Conventional Commits is that format, a short public specification, at version 1.0.0, used by many open-source projects and companies.

The format

Commit message
type(scope): description

optional body

optional footer
PartRuleExample
typeWhat kind of change (the table below)feat
scopeOptional: the part of the code, in brackets(cart)
descriptionWhat it does, in the imperative, lowercase, no full stopadd a promo code field
bodyOptional: why, after a blank linePlain sentences
footerOptional: breaking changes and issue linksCloses #12

The description follows the same rule as any good commit message (Lesson 5): it completes “If applied, this commit will…”.

The types

TypeForExample
featA new feature users can seefeat: add dark mode
fixA bug fixfix: stop double form submits
docsDocumentation onlydocs: explain the env variables
styleFormatting, no change in behaviourstyle: run prettier
refactorRestructuring, no change in behaviourrefactor: split the cart hook
perfFaster or lighterperf: lazy-load the map
testAdding or fixing teststest: cover empty carts
buildBuild tools and dependenciesbuild: upgrade to react 19
ciCI configurationci: cache npm installs
choreOther upkeepchore: update the gitignore
revertUndoing an earlier commitrevert: add dark mode

Only feat and fix are in the specification itself. The others come from the widely used @commitlint/config-conventional rules, which most teams adopt.

Breaking changes

A change that breaks existing users gets a ! after the type or scope, a BREAKING CHANGE: footer, or both:

Commit message
feat(api)!: return prices in cents

BREAKING CHANGE: the price field is now an integer number of cents,
not a decimal amount in dollars.

From commits to versions

The types line up with semantic versioning (Lesson 24), so tools like semantic-release and release-please can pick the next version by reading the commits since the last tag:

Commits since v1.4.2 includeNext version
Only fixv1.4.3 (patch)
At least one featv1.5.0 (minor)
A breaking change (! or BREAKING CHANGE:)v2.0.0 (major)
Only docs, chore, test…No release

The same tools group the commits into release notes: Features, Bug Fixes, Breaking Changes.

With squash merging

When a team squash-merges (Lesson 21), the pull request title becomes the commit on main. Then the title is what has to follow the format, like feat(cart): add a promo code field, and the commits inside the branch can be more relaxed.

Quick reference

NeedMessage
New featurefeat: add search
Bug fix in one areafix(cart): keep the total
Breaking changefeat(api)!: rename the user endpoint
Upkeepchore: update dependencies
Docsdocs: add setup steps
Close an issueFooter: Closes #12