Dev tools and workflow · Intermediate · 20 min
Version releases with semantic versioning, Git tags and a changelog
By Padding · Updated 26 Nov 2026
Ubuntu 26.04 · Git 2.53 (Ubuntu package)
You will take a small shell library from 1.0.0 to 1.1.0 with written version rules, Conventional Commits, a Keep a Changelog file, annotated Git tags, a build stamped by git describe and release notes drafted from the commits since the last tag.
On this page
A version number is a promise. When a library goes from 1.4.2 to 1.4.3, the people who depend on it expect to upgrade without reading anything. When it goes to 2.0.0, they expect to read the notes first. That promise only holds if you decide in advance what each part of the number means, write it down, and record each release in a way that people and tools can both read.
In this tutorial you release slugkit, a tiny library of shell functions that turn text into URL slugs. It is small on purpose, so the attention goes on the release work: the rules for major, minor and patch, commit messages a script can sort, a changelog, annotated tags, a build that knows its own version, and release notes drafted from the history. None of it depends on the language. The same steps work for a Python package, a Go module or a design-token file.
The commands were checked with the Git package in Ubuntu 26.04, which is 2.53. The current upstream release is 2.56, and everything shown works on 2.53 or newer.
Step 1 · Create a small library to release
Make a throwaway folder and a repository with an explicit main branch:
mkdir -p ~/release-demo/slugkit
cd ~/release-demo/slugkit
git init -b mainWrite the library. It has one function, and one deliberate bug: the pattern keeps letters but forgets digits. You fix it later as a patch release.
cat > slug.sh <<'SH'
# slugkit: turn a line of text into a URL slug.
slugify() {
printf '%s\n' "$1" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z]+/-/g; s/^-+//; s/-+$//'
}
SHAdd a small test runner. It loads the library, runs every file in tests/, and reports each check:
mkdir -p tests
cat > test.sh <<'SH'
#!/bin/sh
set -eu
. ./slug.sh
failed=0
check() {
if [ "$1" = "$2" ]; then echo "ok $2"; else echo "FAIL got '$1', want '$2'"; failed=1; fi
}
for t in tests/*.sh; do . "./$t"; done
[ "$failed" -eq 0 ] || { echo "tests failed"; exit 1; }
echo "all tests passed"
SH
cat > tests/slugify.sh <<'SH'
check "$(slugify 'Hello World')" "hello-world"
check "$(slugify ' Lagos -- Accra ')" "lagos-accra"
SH
printf 'dist/\n' > .gitignore
sh test.shCommit it. The feat: prefix on the message is explained two steps from now:
git add slug.sh test.sh tests .gitignore
git commit -m "feat: add slugify"Check it worked
sh test.sh printed two ok lines and all tests passed. Confirm the commit:
git log --onelineOne commit, with the subject feat: add slugify.
Step 2 · Decide what each part of the version promises
Semantic Versioning 2.0.0 (SemVer) gives a version three numbers, MAJOR.MINOR.PATCH, and ties each one to a kind of change in your public API. The spec does not tell you what your public API is. You have to say, and the README is where people look. Write one:
cat > README.md <<'MD'
# slugkit
Small POSIX shell functions that turn text into URL slugs.
## Public API
Every function in slug.sh whose name does not start with an underscore,
its arguments, its output and its exit status.
slugify TEXT prints TEXT as a slug: lower-case ASCII letters and digits,
with each run of other characters replaced by one hyphen.
## Versioning
slugkit follows Semantic Versioning 2.0.0.
- MAJOR: a public function is removed or renamed, takes different
arguments, or gives different output or exit status for input that
worked before.
- MINOR: a new function or option. Existing calls behave as before.
- PATCH: a bug fix that makes a function match this README, nothing else.
MDThree rules sit behind those lines, and they are the ones people get wrong:
- Changing output is a change to the API. Your users store slugs in databases and URLs. If
slugifystarts producing different text for the same input, old links break. That is a major change, even if the code change is one character. The exception is a bug: output that never matched the documented behaviour. The digits bug is one, because the README says digits are kept. - 0.y.z means "no promises yet". Before 1.0.0, anything may change at any time (SemVer item 4). Many projects treat a 0.x minor bump as "may break" and a 0.x patch bump as "safe". Releasing 1.0.0 says the public API is now defined (item 5). Do it once people depend on you, not when the code feels finished.
- Removing something takes two releases. Mark it deprecated in a minor release and say what to use instead, then remove it in the next major. People get one release to move.
SemVer also defines two optional suffixes. A pre-release adds a hyphen and dot-separated identifiers, such as 1.1.0-rc.1 or 2.0.0-beta.3. A pre-release sorts before its plain version: 1.1.0-rc.1 is lower than 1.1.0, and package managers do not pick it unless asked. Build metadata adds a plus sign, such as 1.1.0+20261118.abc1234. It records where a build came from and is ignored when comparing versions, so 1.1.0+a and 1.1.0+b count as the same version.
A note for multilingual text: slugify keeps only ASCII letters, so a Yoruba place name such as Ọ̀ṣun State loses its first letters and becomes something like un-state. Transliterating it to osun-state would be kinder, but it changes the output for input that already "worked". Under the rules above that is a major release, or a new function such as slugify_translit in a minor one. Deciding that in advance is the point of writing the rules down.
Check it worked
grep -nE '^- (MAJOR|MINOR|PATCH)' README.mdThree lines, one for each part of the version. If your project has a public API that the README does not describe, write that section before you release 1.0.0.
Step 3 · Write commit messages a script can read
Conventional Commits 1.0.0 is a format for commit subjects: type(scope): description, with the scope optional. Two types map straight onto SemVer:
feat:adds a feature, which means a minor release.fix:fixes a bug, which means a patch release.
A ! before the colon (feat!: or fix(api)!:), or a footer that starts with BREAKING CHANGE:, marks a breaking change, which means a major release. Other types such as docs:, test:, refactor: and chore: are allowed and do not trigger a release on their own. Commit the README with one:
git add README.md
git commit -m "docs: describe the public API and the versioning rules"The format pays off later, when a script groups the history into release notes. It also makes the reader of git log think about the size of each change before pushing it. pre-commit can also run a hook at the commit-msg stage to check the format; run checks before every commit with pre-commit shows how hook stages work.
Check it worked
git log --format='%s'Both subjects start with a type and a colon: docs: describe ... on top, feat: add slugify below it.
Step 4 · Start a changelog with an Unreleased section
Commit messages are written for developers at the moment of the change. A changelog is written for the people who upgrade, at release time. Keep a Changelog 1.1.0 is a plain format for it: newest release first, an Unreleased section at the top that collects changes as they land, and changes grouped under Added, Changed, Deprecated, Removed, Fixed and Security.
You would normally edit CHANGELOG.md in your editor. Here a heredoc writes the exact content:
cat > CHANGELOG.md <<'MD'
# Changelog
All notable changes to slugkit are recorded here. The format follows
Keep a Changelog 1.1.0 and the project uses Semantic Versioning 2.0.0.
## [Unreleased]
### Added
- slugify turns a line of text into a lower-case, hyphen-separated slug.
MD
git add CHANGELOG.md
git commit -m "docs: start a changelog"The habit that keeps a changelog alive: every pull request that changes behaviour adds its line under Unreleased in the same pull request. At release time you rename the section instead of digging through weeks of history.
Check it worked
grep -nE '^#{2,3} ' CHANGELOG.mdYou see ## [Unreleased] with ### Added under it.
Step 5 · Release 1.0.0 with an annotated tag
A release has two parts: the changelog says what changed, and a tag marks the exact commit. Rename Unreleased to the version and date, start a new empty Unreleased section, and add links at the bottom. Replace example.com/you/slugkit with your repository's address when you do this for real:
today=$(date +%F)
cat > CHANGELOG.md <<MD
# Changelog
All notable changes to slugkit are recorded here. The format follows
Keep a Changelog 1.1.0 and the project uses Semantic Versioning 2.0.0.
## [Unreleased]
## [1.0.0] - $today
### Added
- slugify turns a line of text into a lower-case, hyphen-separated slug.
[unreleased]: https://example.com/you/slugkit/compare/v1.0.0...HEAD
[1.0.0]: https://example.com/you/slugkit/releases/tag/v1.0.0
MD
git commit -am "chore(release): 1.0.0"Dates use the ISO form YYYY-MM-DD, which reads the same in Lagos, Nairobi and London. Now tag the release commit:
git tag -a v1.0.0 -m "slugkit 1.0.0"-a makes an annotated tag: a Git object of its own with the tagger, a date and a message. Without -a, git tag v1.0.0 makes a lightweight tag, which is only a name pointing at a commit. Use annotated tags for releases. git describe ignores lightweight tags by default, git push --follow-tags only pushes annotated ones, and an annotated tag can be signed with git tag -s so people can check who made the release. The v prefix is a Git convention, not part of the version: the version is 1.0.0, the tag is v1.0.0.
Check it worked
git cat-file -t v1.0.0
git show --no-patch v1.0.0The first command prints tag. A lightweight tag would print commit. The second shows the tag header, with Tagger: and the message slugkit 1.0.0, followed by the chore(release): 1.0.0 commit it points at.
Step 6 · Ship a release candidate, then 1.1.0
Two changes arrive. First, a new function that cuts a slug to a maximum length. It is new and changes nothing existing, so it is a minor change:
cat >> slug.sh <<'SH'
slugify_max() {
slugify "$1" | cut -c "1-$2"
}
SH
cat > tests/slugify_max.sh <<'SH'
check "$(slugify_max 'Hello World' 5)" "hello"
SH
sh test.sh
git add slug.sh tests
git commit -m "feat: add slugify_max to limit slug length"Second, the digits bug from the first step. The fix makes slugify match the README, so it is a patch-level change. The whole file is rewritten here so the result is exact:
cat > slug.sh <<'SH'
# slugkit: turn a line of text into a URL slug.
slugify() {
printf '%s\n' "$1" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//'
}
slugify_max() {
slugify "$1" | cut -c "1-$2"
}
SH
cat > tests/digits.sh <<'SH'
check "$(slugify 'Top 10 tips')" "top-10-tips"
SH
sh test.sh
git add slug.sh tests
git commit -m "fix: keep digits in slugs"A feat and a fix together make the next version 1.1.0: the largest change wins. Before calling it final, tag a release candidate so a few users can try it:
git tag -a v1.1.0-rc.1 -m "slugkit 1.1.0 release candidate 1"A tester finds a problem: cutting at a hyphen leaves one at the end. Fix it, with a test:
cat > slug.sh <<'SH'
# slugkit: turn a line of text into a URL slug.
slugify() {
printf '%s\n' "$1" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//'
}
slugify_max() {
slugify "$1" | cut -c "1-$2" | sed -E 's/-+$//'
}
SH
cat > tests/slugify_max_hyphen.sh <<'SH'
check "$(slugify_max 'Lagos to Accra' 9)" "lagos-to"
SH
sh test.sh
git add slug.sh tests
git commit -m "fix(slugify_max): drop a trailing hyphen after cutting"The fix happened inside the release candidate, so 1.1.0 users never see the bug. The changelog describes the change from 1.0.0 to 1.1.0, and leaves this one out. Write the 1.1.0 entry. The 1.0.0 date is read from the tagged commit, so it stays exactly as it was:
today=$(date +%F)
v100_date=$(git log -1 --format=%as v1.0.0)
cat > CHANGELOG.md <<MD
# Changelog
All notable changes to slugkit are recorded here. The format follows
Keep a Changelog 1.1.0 and the project uses Semantic Versioning 2.0.0.
## [Unreleased]
## [1.1.0] - $today
### Added
- slugify_max cuts a slug to a maximum length without leaving a trailing hyphen.
### Fixed
- slugify keeps digits: "Top 10 tips" now gives top-10-tips instead of top-tips.
## [1.0.0] - $v100_date
### Added
- slugify turns a line of text into a lower-case, hyphen-separated slug.
[unreleased]: https://example.com/you/slugkit/compare/v1.1.0...HEAD
[1.1.0]: https://example.com/you/slugkit/compare/v1.0.0...v1.1.0
[1.0.0]: https://example.com/you/slugkit/releases/tag/v1.0.0
MD
git commit -am "chore(release): 1.1.0"
git tag -a v1.1.0 -m "slugkit 1.1.0"Check it worked
List the tags in version order:
git tag --list --sort=v:refnamePlain git tag sorts by text, which puts v1.10.0 before v1.9.0 once you get that far. v:refname compares the numbers as numbers. It still lists v1.1.0 before v1.1.0-rc.1, though, because Git does not know that -rc means "earlier". Tell it, for this repository:
git config versionsort.suffix -rc
git tag --list --sort=v:refnameNow the order is v1.0.0, v1.1.0-rc.1, v1.1.0, which matches SemVer precedence. If you use more than one suffix, add each with --add, in the order they come, because a plain git config versionsort.suffix -beta replaces the -rc value instead of adding to it. For -alpha, -beta and -rc that is git config versionsort.suffix -alpha, then git config --add versionsort.suffix -beta and git config --add versionsort.suffix -rc. --sort=-v:refname reverses the list, newest first.
Step 7 · Stamp the version into a build with git describe
The version should come from the tag, not from a number someone types into a file and forgets to change. git describe names the current commit relative to the nearest annotated tag. Write a build script that uses it:
cat > build.sh <<'SH'
#!/bin/sh
# Build dist/slugkit.sh with the version taken from Git.
set -eu
tag=$(git describe --abbrev=0)
desc=$(git describe --dirty)
extra=${desc#"$tag"}
extra=${extra#-}
meta=$(printf '%s' "$extra" | tr '-' '.')
version=${tag#v}${meta:++$meta}
mkdir -p dist
{
printf '# slugkit %s\n' "$version"
printf 'SLUGKIT_VERSION=%s\n' "$version"
cat slug.sh
} > dist/slugkit.sh
echo "built dist/slugkit.sh, version $version"
SH
git add build.sh
git commit -m "build: stamp the version from git describe"
sh build.shOn a tagged commit, git describe prints the tag itself. One commit later it prints something like v1.1.0-1-g3f2a9c1: the tag, the number of commits since it, and g plus the short commit ID. --dirty adds -dirty when tracked files have uncommitted changes. Written as is, 1.1.0-1-g3f2a9c1 would be a SemVer pre-release, which sorts below 1.1.0, the wrong way round. The script moves that part into build metadata instead, as 1.1.0+1.g3f2a9c1, so the version stays 1.1.0 and the build records exactly where it came from.
The build commit came after the tag, so the version you see now has that suffix. Make a change to a tracked file without committing, and build again:
echo "# local experiment" >> slug.sh
sh build.sh
git restore slug.shThe version now ends in .dirty. A dirty build should never be shipped, and having it in the version string makes one easy to spot in a bug report. git restore puts the file back.
Check it worked
sh build.sh
grep -E '^SLUGKIT_VERSION=1\.1\.0\+1\.g[0-9a-f]+$' dist/slugkit.shYou see a line like SLUGKIT_VERSION=1.1.0+1.g3f2a9c1, with no dirty. If the build fails with fatal: No names found, cannot describe anything, the repository has no annotated tags yet. dist/ is in .gitignore, so the build output does not make the tree dirty.
Step 8 · Draft release notes from the commits since the last tag
Because the subjects follow Conventional Commits, a short script can sort them and suggest the next version. First make one more change, a breaking one: slugify now fails when no slug is left, instead of printing an empty line. A caller that relied on the empty line breaks, so the commit has a ! and a BREAKING CHANGE: footer. The second -m becomes the last paragraph of the message, which is where footers go. Use single quotes: inside double quotes, an interactive bash or zsh treats ! as a history command and rewrites or rejects the message.
cat > slug.sh <<'SH'
# slugkit: turn a line of text into a URL slug.
slugify() {
_slug=$(printf '%s\n' "$1" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//')
[ -n "$_slug" ] || return 1
printf '%s\n' "$_slug"
}
slugify_max() {
slugify "$1" | cut -c "1-$2" | sed -E 's/-+$//'
}
SH
cat > tests/empty.sh <<'SH'
if slugify '!!!' >/dev/null; then check "exit 0" "exit 1"; else check "exit 1" "exit 1"; fi
SH
sh test.sh
git add slug.sh tests
git commit -m 'feat!: make slugify fail when no slug is left' -m 'BREAKING CHANGE: slugify now exits with status 1 and prints nothing for input with no letters or digits.'Now the script. It finds the last release tag, reads the commits since then, groups them and works out the bump. Note the 0.x rule: before 1.0.0 a breaking change bumps the minor number.
cat > release-notes.sh <<'SH'
#!/bin/sh
# Draft release notes from Conventional Commits since the last tag.
set -eu
last=$(git describe --abbrev=0)
range="$last..HEAD"
subjects=$(git log --format='%s' "$range")
bodies=$(git log --format='%B' "$range")
if printf '%s\n' "$bodies" | grep -qE '^[a-z]+(\([^)]*\))?!:|^BREAKING[ -]CHANGE:'; then bump=major
elif printf '%s\n' "$subjects" | grep -qE '^feat(\([^)]*\))?:'; then bump=minor
else bump=patch; fi
v=${last#v}; v=${v%%[-+]*}
major=${v%%.*}; rest=${v#*.}; minor=${rest%%.*}; patch=${rest#*.}
case "$bump" in
major) if [ "$major" -eq 0 ]; then minor=$((minor + 1)); patch=0
else major=$((major + 1)); minor=0; patch=0; fi ;;
minor) minor=$((minor + 1)); patch=0 ;;
patch) patch=$((patch + 1)) ;;
esac
echo "Changes since $last. Suggested next version: $major.$minor.$patch ($bump)"
section() {
lines=$(printf '%s\n' "$subjects" | grep -E "$2" || true)
[ -n "$lines" ] || return 0
printf '\n### %s\n\n' "$1"
printf '%s\n' "$lines" | sed -E 's/^[a-z]+(\([^)]*\))?!?: /- /'
}
section "Breaking changes" '^[a-z]+(\([^)]*\))?!:'
section "Added" '^feat(\([^)]*\))?:'
section "Fixed" '^fix(\([^)]*\))?:'
SH
git add release-notes.sh
git commit -m "build: add a release notes script"
sh release-notes.shThe output is a draft, not the finished notes. The build: commits are left out because they do not change what users get. Paste the useful lines under Unreleased in CHANGELOG.md and reword them for someone upgrading. "slugify now exits with status 1 for input with no letters or digits. Check the exit status if you pass user input" is more useful than the commit subject. Always read the draft yourself before release: a mislabelled commit (a breaking change typed as fix:) gives a wrong suggestion, and only a person who knows the change can catch it.
Check it worked
sh release-notes.sh | grep 'Suggested next version: 2.0.0 (major)'The first line suggests 2.0.0, and a Breaking changes section lists make slugify fail when no slug is left. To see the commits behind any release, use the same range by hand, for example git log --oneline v1.0.0..v1.1.0.
Step 9 · Publish the tags and decide what to automate
Tags stay on your machine until you push them. A plain git push does not send them. A local bare repository stands in for GitHub or GitLab here. With a real host, the origin remote is already set when you clone:
git init --bare ~/release-demo/slugkit-remote.git
git remote add origin ~/release-demo/slugkit-remote.git
git push --follow-tags origin main--follow-tags pushes the branch plus every annotated tag on the commits being pushed. To push one tag, use git push origin v1.1.0. Avoid git push --tags as a habit, because it also pushes any stray local tags. Once a release tag is public, do not move or delete it: people have already built from it. If a release is bad, release a fixed version with a higher number.
Check it worked
git ls-remote --tags originThe remote lists refs/tags/v1.0.0, refs/tags/v1.1.0-rc.1 and refs/tags/v1.1.0. Each also appears with ^{} on the end, which is the commit the annotated tag points at.
Tools that automate this
Once the manual process makes sense, tools can run parts of it in CI. They all rely on the conventions you used here:
- release-please reads Conventional Commits and keeps a release pull request open with the next version and changelog. Merging it tags the release.
- semantic-release works out the version from commits and publishes the release from CI without a pull request.
- Changesets asks each pull request to add a small file that states the bump and a line for the changelog. It is common in JavaScript monorepos.
- git-cliff generates a changelog from the history with a template, like a fuller version of
release-notes.sh. - GitHub can draft release notes from merged pull requests when you publish a release from a tag.
Each one still needs a person to check that the bump is right and that the notes make sense to someone upgrading. Start with the manual steps and the written rules, and add a tool when cutting releases by hand becomes the slow part.
Clean up
This deletes the demo repository, its fake remote and everything you built in this tutorial. Nothing outside ~/release-demo was changed apart from your shell history:
cd ~
rm -rf ~/release-demoNext steps
- Make the README that carries your versioning rules worth reading: write a README people actually read.
- Run the tests before each commit, and learn the hook stages a commit-message check would use: run checks before every commit with pre-commit.
- Release from a branch you merged cleanly: create, switch and merge branches in Git.
Related tutorials
- Work on two branches at once with git worktreeYou will fix an urgent bug in a second working tree without stashing your half-finished feature, merge the fix, and clean up every extra tree afterwards.
- Search files and shell history interactively with fzfYou will have fzf 0.75 wired into your shell for history search, file insertion and directory jumps, fed by fd with a preview pane, plus two small pickers that switch Git branches and stop processes.
- Run project tasks with just, a command runnerYou will install just 1.59 and write a justfile for a small site project, with recipes that take parameters, depend on each other, read variables and a .env file, run Python, ask before deleting and list themselves as help.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials