GitHub CLI
gh wraps GitHub APIs for PRs, issues, Actions, and releases from the terminal - the fastest path from cargo test green to review requested.
Recipe
gh auth login
gh pr create --fill --web
gh pr checks
gh run watchWhen to reach for this:
- Creating PRs after
git push - Watching Rust CI matrix without leaving terminal
- Downloading failed workflow logs
- Triggering
workflow_dispatchreleases
Working Example
git push -u origin feat/api-42-health
gh pr create \
--title "feat(api): health route [API-42]" \
--body "Adds /health and /ready for k8s probes." \
--reviewer teammate
gh pr checkout 128
cargo test
gh pr comment 128 --body "cargo test green locally on 1.97.0"
gh run list --workflow ci.yml --limit 3
gh run view <id> --log-failedWhat this demonstrates:
--filluses commit messages for PR title/bodypr checkoutintegrates with local gitrun view --log-failedshows clippy/test failures quickly
Deep Dive
Useful Aliases
gh alias set co 'pr checkout'
gh alias set rv 'pr view --web'Release Assets
gh release create v1.2.0 \
target/release/my-cli-x86_64-unknown-linux-gnu \
--notes-file CHANGELOG.mdGotchas
- Wrong repo remote -
ghtargets origin URL. Fix:gh repo set-default. - Token scope missing - cannot trigger workflows. Fix:
gh auth refresh -s workflow. - PR create on dirty tree - still works but confuses reviewers. Fix: push only intended commits.
- Large log download - slow terminal. Fix:
--log-failedfilter. - Enterprise host - needs
GH_HOSTorgh auth login --hostname.
Alternatives
| Alternative | Use When | Don't Use When |
|---|---|---|
| GitHub web UI | Complex PR templates | Daily create/watch loop |
hub (legacy) | Old scripts | New setups - use gh |
| Graphite / stacked CLI | Stacked PRs workflow | Simple single PR |
FAQs
gh vs git?
git manages objects and refs; gh manages GitHub platform features.
CI from fork PR?
Maintainers use gh workflow run or approve pull_request_target per security policy.
Codespaces?
gh preinstalled; gh cs manages codespaces when enabled.
Related
Stack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.