Sub topic 16
Draft and pre-release states
This chapter assumes you can create a release with gh release create or the web UI, and that you know a release points at a tag. Draft and pre-release are two flags on a release. They change who sees it and how GitHub presents it. They do not change the tag.
Two flags, two purposes
| State | Visible to | Tag created | Shown as latest |
|---|---|---|---|
| Draft | Users with write access only | Not until you publish | No |
| Pre-release | Everyone | Yes | No |
| Full release | Everyone | Yes | Yes, if it is the newest |
A draft is unfinished work. A pre-release is published, but it tells users the version is not ready for general use.
Drafts
Use a draft to prepare notes and upload files before anyone sees them. You can review the generated notes, edit them, and check the attached files. When you publish, the release becomes public.
A draft does not need an existing tag. If the tag is missing when you publish, GitHub creates it on the target commit. For a repeatable release, push the tag first so the commit is fixed.
git push origin v1.2.0
gh release create v1.2.0 --draft --generate-notes ./dist/app.tar.gzTo publish the draft later:
gh release edit v1.2.0 --draft=falsePre-releases
Mark a release as a pre-release when it is a candidate or beta. A common convention is to put the stage in the SemVer suffix, such as v1.2.0-rc.1 or v2.0.0-beta.2.
git tag -a v1.2.0-rc.1 -m "Release candidate 1"
git push origin v1.2.0-rc.1
gh release create v1.2.0-rc.1 --prerelease --generate-notesGitHub does not read the suffix. The --prerelease flag is what sets the state, so you must pass it yourself. A tag named -rc.1 without the flag appears as a normal release.
Pre-releases are skipped when GitHub chooses the "Latest" release. Links to the latest release, and tools that follow them, keep pointing at your last stable version.
When the candidate is accepted, you usually tag the final version as a new release instead of converting the candidate. The final tag, v1.2.0, points at the commit you tested.
Common errors
- Publishing a draft and finding the tag on the wrong commit. Push the tag yourself before creating the draft.
- Forgetting
--prereleaseon a release candidate, which makes it the "Latest" release. - Expecting a draft to be visible to teammates without write access. They cannot see it.
Exercise
You tagged v2.0.0-beta.1 and ran gh release create v2.0.0-beta.1 --generate-notes. Users report that the "Latest" release is now the beta. What went wrong, and what command fixes it?
Show answer
The release was created without --prerelease. GitHub does not infer the state from the tag name, so it treated the beta as a full release. Fix it with gh release edit v2.0.0-beta.1 --prerelease, which marks it as a pre-release and returns "Latest" to the last stable release.