Conventional Commits and semantic versioning

Intermediate · 15 min

Write commit messages in a fixed shape so a tool can read them, and use them to decide the next version number: patch, minor or major.

Before thisWriting good commit messagesTags and releases

Julie Ng · 15 min

Conventional Commits and semantic versioning

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Julie NgReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A Conventional Commit starts with a type, an optional scope in parentheses, and a description, for example fix(cli): handle an empty title.
  • Semantic versioning numbers a release MAJOR.MINOR.PATCH, and the number tells consumers whether upgrading can break them.
  • A fix bumps PATCH, a feat bumps MINOR, and any breaking change bumps MAJOR, whatever its type.
  • A breaking change is marked with an exclamation mark before the colon or a BREAKING CHANGE footer.
  • A commit-msg hook can reject badly shaped messages locally, and a small script or release tool can compute the next version from the log.

Two conventions that fit together

You already know a good commit message explains why a change was made. The trouble is that “good” is a human judgement, so a tool can’t use it. Look at a month of history and ask a computer “did anything in here break users?” and it has nothing to go on.

Conventional Commits fixes this by giving the first line a fixed shape. Semantic versioning (SemVer) gives version numbers a fixed meaning. Together they let a script read the log and say “the next release is 1.5.0”. Neither convention is required by Git. Each is a team agreement that tooling can enforce.

The shape of a commit

<type>[optional scope][!]: <description>

[optional body]

[optional footer(s)]

Some real examples from the notes CLI:

fix(cli): handle an empty note title
feat(cli): add --tag option
docs: explain the tag option
refactor(api)!: rename list to ls

BREAKING CHANGE: the list command is now ls

The type says what kind of change it is. The spec requires two: feat for a new feature and fix for a bug fix. Others are allowed, and the common set (from the Angular convention) is build, chore, ci, docs, style, refactor, perf and test. The scope is a noun in parentheses naming the area touched. The ! before the colon, or a BREAKING CHANGE: footer, marks a change that breaks existing users. That footer token must be uppercase. I checked these rules against the Conventional Commits 1.0.0 page on 2026-11-23.

Semantic versioning

A version is three numbers, MAJOR.MINOR.PATCH. The meaning matters more than the format.

  • PATCH goes up for backward-compatible bug fixes. Upgrading should be safe.
  • MINOR goes up for backward-compatible new features. Upgrading should be safe, and you may want the new thing.
  • MAJOR goes up for incompatible changes. Upgrading may break you, so read the notes first.

Raising MINOR resets PATCH to 0, and raising MAJOR resets both. Versions below 1.0.0 mean initial development, where anything can change at any time. A pre-release looks like 1.0.0-rc.1 and sorts below 1.0.0. Once a version is released it is never edited, and a fix means a new version. Check the details on semver.org.

SemVer is a promise to the people who depend on you. A dependency manager can only be trusted to accept “any 1.x release” if 1.x really never breaks. That is why the mapping from commits is mechanical: fix gives PATCH, feat gives MINOR, and any breaking change gives MAJOR, whatever its type.

Running it for real

I tried this in a scratch repository with git 2.54, and both halves worked as described.

Enforcing the shape. A commit-msg hook receives the path of the message file and fails the commit if the first line doesn’t match:

#!/bin/sh
head -n1 "$1" | grep -Eq '^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9-]+\))?!?: .+' || {
  echo "commit message must look like 'type(scope): description'" >&2; exit 1; }

Saved as .git/hooks/commit-msg and made executable, it rejected added stuff with exit code 1 and accepted chore: initial commit. It also rejected Feat: capital, which the spec would allow, so this hook is stricter than the standard. Hooks live in .git/ and are not shared by git clone, so a team enforces the same rule in CI as well. Git hooks get their own lesson in the Inside Git group.

Computing the next version. After tagging v1.0.0, I committed a fix, a feat and a docs commit. This script walks the log since the last tag:

import { execFileSync } from "node:child_process";
const git = (...a) => execFileSync("git", a, { encoding: "utf8" }).trim();
const last = git("describe", "--tags", "--abbrev=0");
const log = git("log", `${last}..HEAD`, "--format=%B%x00").split("\0").map(s => s.trim()).filter(Boolean);
let level = 0; // 1 patch, 2 minor, 3 major
for (const msg of log) {
  const head = msg.split("\n")[0];
  if (/^\w+(\([^)]*\))?!:/.test(head) || /^BREAKING CHANGE: /m.test(msg)) level = 3;
  else if (/^feat(\(|:)/.test(head)) level = Math.max(level, 2);
  else if (/^(fix|perf)(\(|:)/.test(head)) level = Math.max(level, 1);
}
const [maj, min, pat] = last.replace(/^v/, "").split(".").map(Number);
const next = level === 3 ? [maj + 1, 0, 0] : level === 2 ? [maj, min + 1, 0] : level === 1 ? [maj, min, pat + 1] : null;
console.log(next ? `v${next.join(".")}` : `no release (only docs/chore since ${last})`);

It printed v1.1.0. After an empty commit with an ! and a BREAKING CHANGE footer it printed v2.0.0. After tagging that and adding only a docs: commit, it printed no release. This script treats perf as a patch, which is a common tool choice but not in the spec. In real projects you rarely write it yourself; tools such as release-please and semantic-release do this and also write the changelog and tag.

What the video covers

Julie Ng’s “Version and Automate Releases like a Pro - Walkthrough and Demo” is about 15 minutes and was published around 2022. Going by its title and description, it demonstrates automating versioning and releases and argues that experienced engineers should deviate from a standard when they have good reason. I could not read a transcript, so I can’t say which release tool it uses or how it treats the footer rules above. It is older than the rest of this group, though the conventions it builds on have not changed. English is judged from the title and description. Two short explainers, one on each convention, are linked under deeper if you want the basics in isolation.

Where this fits

Version numbers are usually attached to Git tags, and on GitHub to releases with notes. You have seen tags already in tags and releases. The next group moves to GitHub itself, starting with how you prove who you are: GitHub accounts, SSH keys and authentication.

Check yourself

  1. 01What version follows 1.4.2 if the commits since the tag are one fix and one feat?

    1.5.0. The feat is the biggest change, so it bumps MINOR and resets PATCH to zero.

  2. 02How do you mark a breaking change in a Conventional Commit?

    Put an exclamation mark before the colon, as in refactor(api)!: rename list to ls, or add a BREAKING CHANGE footer describing it. Either one makes it a MAJOR bump.

  3. 03Why do semantic versions only help if people follow the rules?

    Consumers decide how careful to be from the number alone. If a MINOR release breaks them, they stop trusting the number and have to read every changelog.

  4. 04Do docs: and chore: commits trigger a release?

    Not by themselves. The spec gives no version effect to types other than feat and fix unless they carry a breaking change.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark