What problem does it solve?
Reference for using the GitHub CLI (gh) to interact with GitHub. Use when working with pull requests, issues, CI runs, releases, or the GitHub API from the command line.
Core Features & Use Cases
- Top-level commands are pr, issue, run, release, search, repo, and api; each has subcommands discoverable with --help.
- Avoiding interactive prompts: Always pass --title and --body when creating PRs or issues, and use --no-pager or pipe through cat when output might be long, since interactive paging blocks automated flows.
- Structured output: Many gh commands support --json <fields> for machine-readable output. Pass --json with no arguments to discover which fields are available. Once in JSON mode, chain --jq to filter or reshape. Prefer this over parsing the human-readable table output — it's stable across versions.
- Investigating PRs and issues: When summarizing or investigating a PR, always fetch comments and reviews alongside metadata — the conversation is often where the real context lives.
- Search: gh search prs, gh search issues, gh search code, gh search commits. Use --repo OWNER/REPO to scope, and -- before any query containing - to prevent flag parsing (e.g. gh search issues --repo OWNER/REPO -- "-label:bug").
- The gh api escape hatch: gh api <endpoint> covers anything without a dedicated command. {owner} and {repo} placeholders auto-resolve from the current repo's git remote. Key flags: -X, -f, -F, --jq, --paginate, --slurp (combine paginated arrays), --cache <duration>, --verbose (dump full HTTP request/response).
- Cross-repo targeting: -R OWNER/REPO on any command, or the GH_REPO env var, targets a repo other than the one in the current directory.
- Environment variables worth knowing: GH_TOKEN / GITHUB_TOKEN, GH_DEBUG=api, NO_COLOR.
Quick Start
Authenticate with GitHub using gh auth status, then try gh pr view --help to discover available commands.