Version and tag releases with semver, git tags and gh release
Releasing by tag means you pick a semantic version, create an annotated git tag such as v1.2.0, push it, and let a workflow build, tag and publish that exact commit.
- Updated Nov 27, 2026
- Markdown
Cut a release by pushing an annotated version tag that triggers a workflow, tags the image and creates a GitHub release.
- A GitHub repository with an image build workflow
- The gh CLI, or use the GitHub web UI
A release is a named point in your history that you can build again exactly. In Git that name is a tag, and in a pipeline the tag becomes the trigger: push v1.2.0, and a workflow builds the image, tags it 1.2.0 and publishes a release. This lesson covers the version number, the tag commands, the workflow and the changelog. It extends the workflow from Build and push a Docker image to GHCR.
How it works#
Semantic versioning writes versions as MAJOR.MINOR.PATCH, for example 1.4.2. You raise MAJOR when you break compatibility, MINOR when you add something compatible, and PATCH when you fix something compatible. A git tag attaches that version to one commit. A push of that tag fires the workflow, which reads the tag name from the git ref and uses it to name the image and the release. Because the tag fixes the commit, the artifact is reproducible. The image tag glossary entry covers the container side.
Step 1: Choose the version#
Look at what changed since the last tag:
- breaking change to a public API, config format or behavior people rely on: bump MAJOR (2.0.0)
- new feature that keeps existing use working: bump MINOR (1.5.0)
- fix only: bump PATCH (1.4.3)
Before 1.0.0, many projects treat the rules loosely. For an app that is not a library, pick a rule you can explain and stick to it. A v prefix on the tag (v1.4.3) is a common convention and is what the workflow pattern below expects.
Step 2: Create an annotated tag#
Make sure you are on the commit you want to release and that it passed CI:
git checkout main
git pull
git tag -a v1.2.0 -m "Release 1.2.0"
git show v1.2.0-a makes an annotated tag, a real Git object with the author, date and message. Releases should use annotated tags, not lightweight ones. git show v1.2.0 prints the tag and the commit it points at. Check that it is the commit you meant.
Step 3: Push the tag#
git push origin v1.2.0A plain git push does not send tags. Push one tag by name. Avoid pushing all tags at once, because old local tags you forgot about would be published too. The push is also the trigger, so do it only when you are ready to release.
Step 4: Trigger a workflow on the tag#
Extend the workflow to react to version tags. This one builds the image and creates a GitHub release:
name: release
on:
push:
tags: ['v*']
permissions:
contents: write
packages: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Lowercase image name
run: echo "IMAGE=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"
- id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
tags: |
type=semver,pattern={{version}}
type=sha
- uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Create GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release create "$GITHUB_REF_NAME" --generate-notes --title "$GITHUB_REF_NAME"contents: write is needed to create the release (see Secrets and variables in CI pipelines on scoping the token), so it sits here and not in your test workflow. fetch-depth: 0 fetches full history so tools that read it can see earlier tags. The metadata action turns v1.2.0 into the image tag 1.2.0, and also adds the SHA tag. The gh release create command is available on GitHub-hosted runners.
Step 5: Build the changelog#
A changelog tells users what changed. Three options:
- Generated notes.
--generate-noteslists merged pull requests since the previous release. - Conventional commits. If your commit messages follow a pattern such as
feat: add exportandfix: handle empty input, tools can group them into features and fixes and even suggest the next version. That works only when the team follows the pattern consistently. - Hand-written notes. Short and human, best for user-facing changes. Pass them with
--notes-file CHANGELOG-1.2.0.md.
Whichever you pick, and whatever Git workflow you follow, keep it based on what changed for the user, not a raw commit dump.
Check it worked#
After the push, open the Actions tab and watch the release run for the tag. When it finishes, the repository’s Releases page should list v1.2.0 with notes. The package page should show the 1.2.0 image tag. Verify from a server:
docker pull ghcr.io/myorg/myapp:1.2.0Replace the owner and image with yours. Also run git ls-remote --tags origin to see the tag on the remote.
Edge cases and gotchas#
- Do not move or delete a published tag. People have pulled it, images and caches were built from it, and release notes point at it. If a release is bad, ship
v1.2.1instead. Fix forward. - Tag the right commit. A tag on a commit that never passed CI releases untested code. Tag from the main commit that is green.
- Deleting a remote tag needs a deliberate command (
git push origin --delete v1.2.0), and it does not unpublish images. Treat it as a last resort, and only for a tag nobody has used. - Tag pattern too loose.
'v*'also matchesvnext. Use a stricter glob such as'v[0-9]*'if you have odd tag names. - Release workflows need write rights. Keep
contents: writeout of workflows that run on pull requests. - Pre-releases. Tags like
v1.3.0-rc.1are valid semver pre-releases. Pass--prereleasetogh release createfor them.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
| Pushed tag but no workflow ran | Tag pattern does not match, or file not on that commit | Check tags: and that the workflow exists at the tagged commit |
error: src refspec v1.2.0 does not match any | Tag was never created locally | Run git tag -a ... first |
fatal: tag 'v1.2.0' already exists | Tag name reused | Choose a new version, do not overwrite |
HTTP 403: Resource not accessible by integration on release | Token lacks contents: write | Add the permission in the release workflow |
| Image tag missing the version | Not a semver-looking tag | Use v1.2.0 style tags |
| Changelog is empty | No merged PRs since the last tag | Write notes by hand |
| Tag shows the wrong commit | Tagged before pulling | Fix forward with a new version, do not move the tag |
Quick reference#
git tag -a v1.2.0 -m "Release 1.2.0"
git show v1.2.0
git push origin v1.2.0
git ls-remote --tags origin
gh release create v1.2.0 --generate-notesRelated lessons#
- Build and push a Docker image to GHCR: the image part of this workflow.
- Git remotes: push, pull and fetch: how pushes and tags reach the remote.
- Undo mistakes in Git: fixes that do not rewrite published history.
- Git workflow that triggers a deploy: the branch flow before the tag.
- Rollback and release strategy in a pipeline: what to do when a release is bad.
Next#
Continue with Rollback and release strategy in a pipeline.
Check what you learned
Frequently asked questions
What is semantic versioning?
A version number in the form MAJOR.MINOR.PATCH. Increase MAJOR for breaking changes, MINOR for backward-compatible features and PATCH for backward-compatible fixes.
What is the difference between a lightweight and an annotated git tag?
A lightweight tag is just a name pointing at a commit. An annotated tag is a full object with a tagger, date and message, created with git tag -a, and it is the right choice for releases.
How do I trigger a GitHub Actions workflow when I push a tag?
Use on push with tags set to a pattern such as 'v*'. Pushing a tag like v1.2.0 then starts the workflow for that tag.
Can I delete or move a release tag?
You can technically, but you should not. Anyone who already pulled the tag, and any image or package built from it, still refers to the old commit, so moving it creates confusion and breaks reproducibility.
Sources
Keep going: guides and tutorials
- Deploy a Docker Compose App Self-Hosted: Web, Redis and Rollback Deploy a Docker Compose app on your own server with Levelrail: a web service and Redis, a bad release that does not take traffic, and a compose rollback.
- Zero Downtime Deploy for Docker Apps, With Rollback How a Docker deploy waits for readiness before cutover, holds the previous release for rollback, rolls back on its own, and how to rehearse it.