Sub topic 13
Creating a Release in the Web UI and with the gh CLI
This chapter assumes you can create and push Git tags, know the difference between lightweight and annotated tags, and have a GitHub repository you can push to. A GitHub Release is a page attached to a tag. It holds a title, notes and optional downloadable files.
What a release needs
A release always points at a tag. If the tag does not exist on GitHub yet, GitHub can create it for you from a branch or commit when you publish. The tag name is the identity of the release, so choose it carefully (for example v1.1.0).
Creating a release in the web UI
- Open the repository on GitHub and click Releases in the right sidebar.
- Click Draft a new release.
- In the tag field, pick an existing tag or type a new one. For a new tag, choose the target branch or commit.
- Enter a title, such as
Version 1.1.0. - Write the notes, or use the button that generates them automatically.
- Click Publish release.
The web UI is useful for one-off releases and for reviewing notes before they go public.
Creating a release with the gh CLI
The gh CLI does the same work from the terminal, which makes it scriptable. Log in once with gh auth login.
# Push the tag first so the release uses the exact commit you tagged
git push origin v1.1.0
# Create the release from that tag
gh release create v1.1.0 --title "Version 1.1.0" --generate-notesIf you run gh release create v1.1.0 and the tag is not on the remote, gh creates it from the default branch's latest commit. That may not be the commit you meant. Pushing the tag first removes the guess.
# Create the tag on a specific commit while releasing
gh release create v1.1.1 --target 4f2a9c1 --title "Version 1.1.1" --notes "Bug fixes"Here --target only applies when the tag does not exist yet.
Useful commands after creation:
gh release list
gh release view v1.1.0Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `tag exists` or release already exists | A release for that tag was already created | Use `gh release edit` or pick a new tag |
| Release points at the wrong commit | `gh` created the tag from the default branch | Push the tag first, or pass `--target` |
| `HTTP 403` or `Resource not accessible` | Token or account lacks write access | Check `gh auth status` and your repository permissions |
| Release missing from the list | It was saved as a draft | Publish the draft |
Exercise
You run gh release create v2.0.0 --generate-notes without having pushed the tag v2.0.0. Your local tag points at a commit on a feature branch. Which commit does the release use, and how do you avoid the problem?
Show answer
GitHub creates the tag from the latest commit of the default branch, not from your local tag. To avoid it, run git push origin v2.0.0 before gh release create, or pass --target with the intended commit.