gh — GitHub, without leaving the terminal

You already git push from the terminal — then alt-tab to the browser to open the PR. gh closes that tab forever: issues, PRs, releases, and the raw API, all one command from where you’re already standing.

gh is GitHub’s own CLI, and the tell is how much of GitHub it covers: not just repo clone and PR list, but gists, Actions runs, releases, projects, and a raw passthrough to the entire REST and GraphQL API. Two things make it stick. First, it’s authenticated — gh auth status knows who you are, and every request carries your token, so you query private repos with the same one-liners you use on public ones. Second, it’s pipe-friendly: --json and --jq turn any listing into exactly the fields you want, ready for a script instead of a screenshot. It doesn’t replace git — it adds the GitHub-shaped half (PRs, issues, API) that git itself doesn’t do.

install

macOS
brew install gh
Debian/Ubuntu
sudo apt install gh
Fedora
sudo dnf install gh
Arch
sudo pacman -S gh
# first run: authenticate (device flow — opens a browser, you
# type a one-time code; no password ever touches the terminal)
gh auth login

examples

# Who am I, which token scopes, is my default keyring working?
gh auth status
# Repo overview without opening a browser tab
gh repo view cli/cli
# Recent issues on any repo (-R works on every gh command)
gh issue list -R octocat/Hello-World --limit 2
# Filter by label and state
gh issue list -R cli/cli --label bug --state open
# Open PRs, machine-readable, one field per line via --jq
gh pr list -R cli/cli --limit 2 --json number,title,author \
  --jq '.[] | "\(.number) \(.author.login): \(.title)"'
# Any REST endpoint: repo metadata, picking fields with --jq
gh api repos/octocat/Hello-World \
  --jq '.description + " | stars: " + (.stargazers_count|tostring)'
# Shortcuts you define: run a whole subcommand with one word
gh alias set co 'pr checkout'      # then: gh co 1234
gh alias set bugs 'issue list --label=bugs'
gh alias list
gh alias delete bugs
# Print the URL instead of opening a browser (-n = no browser)
gh browse -R octocat/Hello-World -n

pro tip

The gh api + --jq pair is the quiet superpower: anything the GitHub website can show you, gh api <endpoint> --jq '<filter>' can print in one line — release assets, workflow runs, review states — with your auth already attached. When you catch yourself opening the API in a browser tab, you’ve found the use case.

honest limits

gh is GitHub-only by design — no GitLab, no Gitea, no self-hosted forge unless it speaks GitHub’s API flavor (GitHub Enterprise does). The alias layer expands commands but doesn’t chain them; a !-shell alias exists, but for real pipelines you’re still in your shell. And the output formats shift between human tables and JSON — scripts should always pass --json explicitly, because the pretty table is for eyes, not parsers.