Sub topic 13
Working with issues from the GitHub CLI
This chapter assumes you can use a terminal, know basic Git and GitHub concepts, and have read the earlier chapters on labels, assignees, and searching issues. The GitHub CLI (gh) lets you do the same work from the command line, so you can script it and avoid switching to the browser.
Setting up
Install gh from the official site, then sign in once:
gh auth login
gh auth statusgh auth login asks how you want to authenticate and stores a token. Run commands inside a cloned repository and gh uses that repository automatically. Outside a clone, add --repo OWNER/NAME to any command.
The core commands
The five commands below cover most daily work.
gh issue create --title "Date field accepts invalid values" --body "Entering 2026-13-45 is saved without an error." --label bug --assignee @me
gh issue list --label bug --state open
gh issue edit 42 --add-label "needs-triage"
gh issue comment 42 --body "Reproduced on main."
gh issue close 42 --comment "Fixed in the latest release."createopens a new issue. Without--titleand--body,ghprompts you step by step.@mestands for your own account.listshows issues. It defaults to open issues, and--stateacceptsopen,closed, orall.editchanges an existing issue. Use--add-labeland--remove-labelfor labels, and--add-assigneeor--milestonefor ownership and grouping.commentadds a comment.closecloses the issue. The--commentflag posts a final note in the same step.
You can also run gh issue view 42 to read an issue in the terminal, or add --web to open it in the browser. gh issue reopen 42 undoes a close.
Filtering from the command line
gh issue list accepts flags such as --label, --assignee, --author, and --milestone. For anything more complex, pass a search query with --search. It uses the same qualifiers you learned in the search chapter:
gh issue list --search "is:open label:bug sort:updated-desc" --limit 10Combine flags and search when you need to. The flags narrow the list, and --search adds the rest.
Scripting with JSON output
Plain output is meant for people. For scripts, ask for JSON with --json and select fields. You can filter the result with --jq.
gh issue list --label bug --json number,title,assignees --jq '.[] | "\(.number)\t\(.title)"'This prints one tab-separated line per bug. Run gh issue list --json with no field names to see which fields exist.
flowchart LRA typical session
A triage pass often follows this order. You list what is new, read one issue, label it, ask for details, and close it if it is a duplicate or already fixed.
Common errors
- Wrong repository. If
ghreports that it cannot determine the repository, run the command inside a clone or add--repo OWNER/NAME. - Label does not exist.
--labeland--add-labelfail when the label is not defined in the repository. Create it first withgh label create. - Missing permission. Editing labels or assignees needs triage or write access. On a repository you do not have that access to, you can create issues and comment, but you cannot edit them.
- Shell quoting. Wrap titles and bodies in quotes. Inside double quotes,
$and backticks are expanded by the shell, so use single quotes when the text contains them.
Exercise
You want a script to print the number and title of every open issue assigned to you. Which command does it, and why use --json instead of parsing the default output?
Show answer
Run gh issue list --assignee @me --json number,title --jq '.[] | "\(.number)\t\(.title)"'. The default output is formatted for reading and can change, while --json returns named fields that a script can parse reliably.