GitHub CLI
Overview
Use gh for day-to-day GitHub operations from the terminal. Prefer read-only commands first, then run mutating commands only after clear user intent.
Quick Start
- Check installation and auth:
gh --version
gh auth status
- Establish repository context:
scripts/gh_preflight.sh --repo owner/repo
- If not in the target repository, pass
-R owner/repo to commands.
- Use
--json with --jq or --template for automation-friendly output.
Workflow
- Establish context first.
- Determine GitHub host (
github.com by default), repository, and branch.
- Run
scripts/gh_preflight.sh before multi-step operations.
- Read current state.
- Use
list, view, and status subcommands before changing anything.
- Apply requested mutation.
- For create/edit/merge/delete actions, restate the operation and require explicit confirmation unless the user already asked clearly.
- Report stable identifiers.
- Return URLs and IDs for created or changed objects (PR number, issue number, run URL, release tag).
Common Commands
- Repository:
gh repo view
gh repo clone owner/repo
gh repo create
gh repo set-default owner/repo
- Pull requests:
gh pr list
gh pr view <number>
gh pr checkout <number>
gh pr create
gh pr review <number> --approve|--request-changes|--comment
gh pr merge <number>
- Issues:
gh issue list
gh issue view <number>
gh issue create
gh issue comment <number> --body "..."
gh issue close <number>
- Actions:
gh workflow list
gh workflow run <workflow>
gh run list
gh run watch <run-id>
gh run view <run-id> --log
- Releases:
gh release list
gh release view <tag>
gh release create <tag> [assets...]
gh release upload <tag> <file>
- API:
gh api repos/{owner}/{repo}/pulls --paginate
For broader command coverage, read references/command-map.md.
Safety Defaults
- Confirm before commands that change remote state:
gh pr create|merge|close|reopen|ready
gh issue create|edit|close|reopen|delete
gh repo create|edit|archive|delete
gh release create|edit|delete
gh secret set|delete
gh variable set|delete
gh workflow run
- Avoid destructive flags (
--delete-branch, force flags) unless explicitly requested.
- Show exact command before bulk updates and prefer smallest safe scope.
Structured Output
Use JSON output when parsing or summarizing results:
gh pr list --json number,title,url --jq '.[] | "\(.number)\t\(.title)\t\(.url)"'
gh issue list --json number,title,labels --template '{{range .}}{{printf "#%v %v\n" .number .title}}{{end}}'
Troubleshooting
- Auth errors:
gh auth login or gh auth refresh.
- Wrong account/host:
gh auth status --hostname github.com, then gh auth switch.
- Unknown command options:
gh <command> <subcommand> --help.
- Manual reference:
https://cli.github.com/manual/.
Resources
scripts/
scripts/gh_preflight.sh: Check gh availability, auth status, and repository context.
references/
references/command-map.md: Command map for repo, PR, issue, actions, release, and API operations.
1---2name: github-113description: Use the GitHub CLI (`gh`) to inspect and manage repositories, pull requests, issues, workflows, releases, and API calls from the terminal. Use when a user asks to use `gh`/GitHub CLI, run GitHub repo or PR workflows, automate GitHub Actions from shell, or troubleshoot `gh` authentication and configuration.4---5
6# GitHub CLI
7
8## Overview
9Use `gh` for day-to-day GitHub operations from the terminal. Prefer read-only commands first, then run mutating commands only after clear user intent.
10
11## Quick Start
121. Check installation and auth:
13```bash
14gh --version
15gh auth status
16```
172. Establish repository context:
18```bash
19scripts/gh_preflight.sh --repo owner/repo
20```
213. If not in the target repository, pass `-R owner/repo` to commands.
224. Use `--json` with `--jq` or `--template` for automation-friendly output.
23
24## Workflow
251. Establish context first.
26- Determine GitHub host (`github.com` by default), repository, and branch.
27- Run `scripts/gh_preflight.sh` before multi-step operations.
282. Read current state.
29- Use `list`, `view`, and `status` subcommands before changing anything.
303. Apply requested mutation.
31- For create/edit/merge/delete actions, restate the operation and require explicit confirmation unless the user already asked clearly.
324. Report stable identifiers.
33- Return URLs and IDs for created or changed objects (PR number, issue number, run URL, release tag).
34
35## Common Commands
36- Repository:
37 - `gh repo view`
38 - `gh repo clone owner/repo`
39 - `gh repo create`
40 - `gh repo set-default owner/repo`
41- Pull requests:
42 - `gh pr list`
43 - `gh pr view <number>`
44 - `gh pr checkout <number>`
45 - `gh pr create`
46 - `gh pr review <number> --approve|--request-changes|--comment`
47 - `gh pr merge <number>`
48- Issues:
49 - `gh issue list`
50 - `gh issue view <number>`
51 - `gh issue create`
52 - `gh issue comment <number> --body "..."`
53 - `gh issue close <number>`
54- Actions:
55 - `gh workflow list`
56 - `gh workflow run <workflow>`
57 - `gh run list`
58 - `gh run watch <run-id>`
59 - `gh run view <run-id> --log`
60- Releases:
61 - `gh release list`
62 - `gh release view <tag>`
63 - `gh release create <tag> [assets...]`
64 - `gh release upload <tag> <file>`
65- API:
66 - `gh api repos/{owner}/{repo}/pulls --paginate`
67
68For broader command coverage, read `references/command-map.md`.
69
70## Safety Defaults
71- Confirm before commands that change remote state:
72 - `gh pr create|merge|close|reopen|ready`
73 - `gh issue create|edit|close|reopen|delete`
74 - `gh repo create|edit|archive|delete`
75 - `gh release create|edit|delete`
76 - `gh secret set|delete`
77 - `gh variable set|delete`
78 - `gh workflow run`
79- Avoid destructive flags (`--delete-branch`, force flags) unless explicitly requested.
80- Show exact command before bulk updates and prefer smallest safe scope.
81
82## Structured Output
83Use JSON output when parsing or summarizing results:
84
85```bash
86gh pr list --json number,title,url --jq '.[] | "\(.number)\t\(.title)\t\(.url)"'
87gh issue list --json number,title,labels --template '{{range .}}{{printf "#%v %v\n" .number .title}}{{end}}'
88```
89
90## Troubleshooting
91- Auth errors: `gh auth login` or `gh auth refresh`.
92- Wrong account/host: `gh auth status --hostname github.com`, then `gh auth switch`.
93- Unknown command options: `gh <command> <subcommand> --help`.
94- Manual reference: `https://cli.github.com/manual/`.
95
96## Resources
97### scripts/
98- `scripts/gh_preflight.sh`: Check `gh` availability, auth status, and repository context.
99
100### references/
101- `references/command-map.md`: Command map for repo, PR, issue, actions, release, and API operations.