What Is the GitHub CLI (gh)? Explained
The GitHub CLI (gh) brings GitHub to your terminal, letting you manage pull requests, issues, releases, and the API without leaving the command line.
gh is GitHub's official command-line tool. It wraps common GitHub operations (opening PRs, reviewing issues, creating releases) and the full REST and GraphQL APIs in convenient commands, which makes it especially useful for scripting and CI automation.
What the GitHub CLI is
gh is a command-line interface for GitHub. It authenticates to your account or, in CI, to a token, and exposes commands for pull requests, issues, releases, gists, workflows, and raw API calls. It complements git: git manages commits, gh manages the GitHub features around them.
How it works
gh authenticates via "gh auth login" or, in automation, by reading a token from the GH_TOKEN environment variable. Commands map to GitHub features ("gh pr create", "gh issue list"), and "gh api" lets you call any REST or GraphQL endpoint directly for things the higher-level commands do not cover.
A usage example
Create a pull request and inspect a workflow run.
# open a PR from the current branch
gh pr create --fill
# view the latest workflow run
gh run list --limit 1
# call the API directly
gh api /repos/owner/repo/releases/latestRole in CI/CD
In CI, gh is preinstalled on GitHub-hosted runners and is the go-to tool for GitHub automation: creating releases, commenting on PRs, dispatching workflows, or querying run status. It reads GH_TOKEN automatically, so scripts authenticate without extra setup. It is the cleanest way to script GitHub interactions inside a pipeline.
Alternatives
Direct calls to the GitHub REST or GraphQL API with curl work but are more verbose. Marketplace GitHub Actions wrap many of the same operations as reusable steps. The Hub tool was an earlier git wrapper. gh is the official, actively maintained CLI and the recommended choice.
Key takeaways
- gh brings GitHub PRs, issues, releases, and the API to the terminal.
- It authenticates via GH_TOKEN, making it ideal for CI scripting.
- In CI it automates releases, PR comments, and workflow dispatch.