Sub topic 4
Creating and triaging issues
This chapter assumes you have gh installed and authenticated (see the chapter on logging in), that you are inside a clone of a GitHub repository or have set GH_REPO, and that you know what an issue and a label are on GitHub.
The issue command group
All issue work lives under gh issue. The subcommands you will use most are create, list, view, edit, comment, close and reopen. Each one takes an issue number or URL, except create and list.
Creating an issue
Run gh issue create with no flags and gh prompts for a title and body. For repeatable work, pass everything as flags.
gh issue create --title "Crash on empty config" --body "Steps to reproduce: run the tool with an empty config file." --label bugThe command prints the URL of the new issue. Useful flags:
| Flag | Purpose |
|---|---|
| `--title`, `-t` | Issue title |
| `--body`, `-b` | Issue body text |
| `--label`, `-l` | Add a label (repeat the flag for several) |
| `--assignee`, `-a` | Assign a user, or `@me` for yourself |
| `--milestone`, `-m` | Attach a milestone by name |
Listing and filtering
gh issue list shows open issues by default. Filters narrow the result.
gh issue list --state open --label bugCombine filters to build a triage queue. For example, --assignee @me shows your work, and --state all includes closed issues. The default limit is 30 results, so raise it with --limit when a repository has many issues.
Reading an issue
gh issue view 42 prints the title, metadata and body in the terminal. Add --comments to include the discussion, or --web to open the issue in your browser.
Triaging with edit, comment and close
Triage means reading new issues, labeling them, assigning an owner and closing the ones that need no action. These commands cover each step:
gh issue edit 42 --add-label "needs-triage" --add-assignee @me
gh issue edit 42 --remove-label "needs-triage" --add-label "confirmed"
gh issue comment 42 --body "Reproduced on v2.3. Working on a fix."
gh issue close 42 --reason "not planned" --comment "Out of scope for this project."--reason accepts completed or not planned. If you closed an issue by mistake, gh issue reopen 42 restores it.
Common errors
- "could not add label: 'x' not found". The label name is misspelled or missing. Run
gh label list, or create it withgh label create. - The list is empty but issues exist. The default state is
open, so closed issues are hidden. Add--state all. - The wrong repository is used.
ghinfers the repository from the current directory's git remotes. Pass--repo owner/name(or-R) to target another one. - "issues disabled". The repository owner has turned off the Issues feature, so
gh issuecommands cannot work there.
Exercises
Exercise
Write one command that lists every issue in the current repository, open or closed, that has the label bug and is assigned to you.
Show answer
gh issue list --state all --label bug --assignee @me
Exercise
You ran gh issue list --label bug and saw no results, yet you know a bug was closed last week. What is the likely cause and the fix?
Show answer
The default state filter is open, so closed issues are excluded. Add --state closed (or --state all) to the command.