Git and GitHub · Part 4 · Team workflows
Conventional commits
Messages machines can read
Compare two histories of the same week:
a1f3c2e updates
9b2d4e1 fixed it
7c8e0f3 new stuff for logina1f3c2e chore: update next to 16.1
9b2d4e1 fix(cart): keep the total after removing an item
7c8e0f3 feat(auth): add sign-in with GitHubThe 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
type(scope): description
optional body
optional footer| Part | Rule | Example |
|---|---|---|
| type | What kind of change (the table below) | feat |
| scope | Optional: the part of the code, in brackets | (cart) |
| description | What it does, in the imperative, lowercase, no full stop | add a promo code field |
| body | Optional: why, after a blank line | Plain sentences |
| footer | Optional: breaking changes and issue links | Closes #12 |
The description follows the same rule as any good commit message (Lesson 5): it completes “If applied, this commit will…”.
The types
| Type | For | Example |
|---|---|---|
feat | A new feature users can see | feat: add dark mode |
fix | A bug fix | fix: stop double form submits |
docs | Documentation only | docs: explain the env variables |
style | Formatting, no change in behaviour | style: run prettier |
refactor | Restructuring, no change in behaviour | refactor: split the cart hook |
perf | Faster or lighter | perf: lazy-load the map |
test | Adding or fixing tests | test: cover empty carts |
build | Build tools and dependencies | build: upgrade to react 19 |
ci | CI configuration | ci: cache npm installs |
chore | Other upkeep | chore: update the gitignore |
revert | Undoing an earlier commit | revert: 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:
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 include | Next version |
|---|---|
Only fix | v1.4.3 (patch) |
At least one feat | v1.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
| Need | Message |
|---|---|
| New feature | feat: add search |
| Bug fix in one area | fix(cart): keep the total |
| Breaking change | feat(api)!: rename the user endpoint |
| Upkeep | chore: update dependencies |
| Docs | docs: add setup steps |
| Close an issue | Footer: Closes #12 |