Tags and releases
Overview
Branches move; releases shouldn’t. When you ship version 1.4.2, you want a permanent name for exactly that commit — so you can rebuild it, compare it with the next version and fix bugs in it later. That’s what tags are for. On GitHub, a release builds on a tag with notes and downloadable files for your users.
Creating tags
git tag -a v1.0.0 -m "Version 1.0.0" # annotated tag on the current commit
git tag -a v0.9.0 -m "Beta" 4f1a2b3 # on an older commit
git tag v1.0.0-local # lightweight tag (just a name)Use annotated tags for releases. They’re full objects that record the tagger, date and message, can be signed (git tag -s), and are what git describe and many tools expect. Lightweight tags are fine for private bookmarks.
Listing and inspecting
git tag # all tags, alphabetical
git tag -l "v1.*" --sort=version:refname # v1.x tags in version order
git show v1.0.0 # tag message plus the commit
git describe --tags # nearest tag: v1.1.0, or v1.1.0-3-g4f1a2b3 (3 commits after)git describe is handy in build scripts to stamp a version into an app: v1.1.0-3-g4f1a2b3 means “3 commits after v1.1.0, at commit 4f1a2b3”.
Sharing tags
git push doesn’t send tags by default. Push them explicitly:
git push origin v1.0.0 # one tag
git push origin main --follow-tags # commits plus the annotated tags that point at them
git push origin --tags # every tag (careful — includes stray local ones)git config --global push.followTags true makes --follow-tags the default. Others get your tags when they fetch.
Deleting and moving tags
git tag -d v1.0.0 # delete locally
git push origin --delete v1.0.0 # delete on the remoteDon’t move or reuse a published tag. People and build systems have already fetched it and expect v1.0.0 to mean one specific commit forever. If a release is broken, release v1.0.1. (Tag rulesets on GitHub can block deleting or updating tags.)
Semantic versioning
Most projects use semantic versioning (semver), MAJOR.MINOR.PATCH:
| Change | Bump | Example |
|---|---|---|
| Breaking change — users must change their code | MAJOR | 1.4.2 → 2.0.0 |
| New feature, backwards compatible | MINOR | 1.4.2 → 1.5.0 |
| Bug fix, backwards compatible | PATCH | 1.4.2 → 1.4.3 |
Before 1.0.0, anything may change. Pre-releases look like 2.0.0-beta.1. Version numbers are a promise to your users about what upgrading will do. Tags conventionally add a v: v1.4.2.
If your team uses Conventional Commits (Writing good commits), tools such as release-please or semantic-release read the commit types since the last tag and choose the next version automatically: any feat!/breaking change → major, any feat → minor, otherwise patch.
GitHub Releases
A release turns a tag into something users can see and download: a title, release notes, and optional files (“assets”) such as compiled binaries. Releases appear on the repository’s front page and can notify watchers.
gh release create v1.1.0 --generate-notes # notes from merged PRs since the last release
gh release create v1.1.0 --title "v1.1.0" --notes-file CHANGELOG.md dist/app.zip
gh release create v2.0.0-beta.1 --prerelease --generate-notes
gh release list--generate-notes builds notes from the pull requests merged since the previous release, grouped and credited to their authors — another reason for clear PR titles. On the website: Releases → Draft a new release, pick or create a tag, click Generate release notes.
Automating releases
A workflow can publish the release whenever you push a version tag:
# .github/workflows/release.yml
name: Release
on:
push:
tags: ["v*"]
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Create GitHub Release
run: gh release create "$GITHUB_REF_NAME" --generate-notes --verify-tag
env:
GH_TOKEN: ${{ github.token }}The gh CLI is preinstalled on GitHub-hosted runners. contents: write lets the token create the release. Real projects add steps before it to test, build and upload assets (or publish to npm, PyPI or a container registry).
Then releasing is two commands:
git tag -a v1.2.0 -m "Version 1.2.0"
git push origin v1.2.0Changelogs
A CHANGELOG.md in the repository, grouped by version with Added / Changed / Fixed sections (see keepachangelog.com), gives users a readable history. Generated release notes, a changelog tool, or both — pick what your users will actually read.
Releases are a promise: a tag never moves, a version number tells users what to expect, and release notes tell them what changed.
Version and release a project
In a repository with a shared server, tag the current commit as v1.0.0 with an annotated tag. Make a bug-fix commit and tag v1.0.1, then a feature commit and tag v1.1.0. Push all tags. List the v1.* tags in version order, show which tag the latest commit is described by, and list the commits between v1.0.0 and v1.1.0 — the raw material for release notes. Finally write a workflow that publishes a GitHub Release with generated notes whenever a v* tag is pushed.
git init -q --bare -b main server.git
git clone -q server.git app 2>/dev/null && cd app
echo "app 1.0" > app.txt && git add . && git commit -qm "feat: first release" && git push -qu origin main
# 1. Tag v1.0.0
# 2. A fix → v1.0.1, a feature → v1.1.0
# 3. Push the tags
# 4. List, describe, compare
# 5. Release workflow: .github/workflows/release.ymlgit init -q --bare -b main server.git
git clone -q server.git app 2>/dev/null && cd app
echo "app 1.0" > app.txt && git add . && git commit -qm "feat: first release" && git push -qu origin main
# 1. Tag v1.0.0
git tag -a v1.0.0 -m "Version 1.0.0"
# 2. A fix → v1.0.1, a feature → v1.1.0
echo "app 1.0 (fixed)" > app.txt && git commit -qam "fix: correct the greeting"
git tag -a v1.0.1 -m "Version 1.0.1"
echo "export" > export.txt && git add . && git commit -qm "feat: add export"
git tag -a v1.1.0 -m "Version 1.1.0"
# 3. Push the tags (and the commits)
git push origin main --follow-tags
# 4. List, describe, compare
git tag -l "v1.*" --sort=version:refname
git describe --tags # v1.1.0
git log --oneline v1.0.0..v1.1.0 # feat: add export / fix: correct the greeting
# 5. Release workflow
mkdir -p .github/workflows
cat > .github/workflows/release.yml <<'EOF'
name: Release
on:
push:
tags: ["v*"]
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Create GitHub Release
run: gh release create "$GITHUB_REF_NAME" --generate-notes --verify-tag
env:
GH_TOKEN: ${{ github.token }}
EOF
git add .github && git commit -qm "ci: publish releases from tags" && git push -qSummary
- Tags give a fixed name to a commit — use annotated tags (
git tag -a) for releases. - Semantic versioning: MAJOR for breaking changes, MINOR for features, PATCH for fixes.
- Tags aren’t pushed by default:
git push origin v1.0.0or--follow-tags. - A GitHub Release attaches notes and downloadable files to a tag;
--generate-noteswrites notes from merged PRs. - Automate releases with a workflow triggered by pushing a
v*tag.