Sub topic 11
Publishing releases
This chapter covers creating GitHub releases from the terminal with gh release. It assumes you can tag and push with Git, are signed in with gh auth login, and know what a pull request is. The chapter runs about 600 words.
What a release is
A release is a GitHub object attached to a Git tag. It has a title, notes, and optional downloadable files, called assets. Tags mark a commit. Releases add a public page and a download area on top of that tag.
gh release create can make the tag for you if it does not exist yet. It creates the tag on the default branch's latest commit unless you pass --target.
Creating a release
The shortest form takes a tag name and asks GitHub to write the notes.
gh release create v1.0.0 --generate-notes--generate-notes builds the notes from the pull requests merged since the previous release. If the tag does not exist, gh creates it. Run this in a clone of the repository, or set GH_REPO to pick the repository.
You can also supply the title and notes yourself.
gh release create v1.1.0 --title "Version 1.1.0" --notes "Fixes the empty config crash."Without --notes or --generate-notes, an interactive session opens and prompts you for the title and notes.
Common options
| Flag | Effect |
|---|---|
| `--generate-notes` | Writes notes from merged pull requests |
| `--notes-file FILE` | Reads the notes from a file |
| `--draft` | Saves the release without publishing it |
| `--prerelease` | Marks the release as a pre-release |
| `--target BRANCH` | Chooses the branch or commit used for a new tag |
| `--latest` | Marks the release as the latest one |
Use --draft when you want to review the page in the browser before anyone sees it.
Attaching assets
List files after the tag name to upload them with the release.
gh release create v1.2.0 ./dist/app-linux.tar.gz ./dist/app-macos.tar.gz --generate-notesYou can add files to an existing release later with gh release upload.
gh release upload v1.2.0 ./dist/app-windows.zipIf a file with the same name already exists, the upload fails. Add --clobber to replace it.
Inspecting and downloading releases
gh release list
gh release view v1.2.0
gh release download v1.2.0 --pattern "*.tar.gz"gh release list shows recent releases and marks drafts and pre-releases. gh release view prints the notes and assets. gh release download fetches assets, and --pattern limits the download to files matching a glob.
Where releases fit in a workflow
A typical flow merges pull requests, tags the result, then publishes. Notes generated at the end of that flow list the merged work.
To publish a draft from the terminal, edit it.
gh release edit v1.2.0 --draft=falseCommon errors
- Release already exists for the tag.
gh release createfails if a release exists for that tag. Usegh release editto change it. - Notes cover too little or too much. Generated notes compare against the previous release. If you skipped a tag or created releases out of order, the range may be wrong. Pass
--notes-start-tagto set the starting point. - Tag points at the wrong commit. A new tag lands on the default branch head. If you were working on another branch, pass
--target. - HTTP 403 or 404. Your account needs write access to the repository. Check
gh auth status.
Exercise
You have built dist/app.zip and want to publish tag v2.0.0 as a draft with generated notes, review it, and then publish it. Which commands do you run?
Show answer
Run gh release create v2.0.0 ./dist/app.zip --generate-notes --draft to create the draft with the asset. After reviewing it, run gh release edit v2.0.0 --draft=false to publish it.
Exercise
A release for v2.0.0 exists, but the app.zip you uploaded was built from the wrong source. How do you replace the file?
Show answer
Run gh release upload v2.0.0 ./dist/app.zip --clobber. Without --clobber, the upload fails because a file with that name already exists.