GitHub CLI (gh) is the official command-line tool for interacting with GitHub from your terminal, enabling repository management, issue tracking, pull request workflows, and GitHub Actions operations without leaving the command line. It eliminates context switching by bringing GitHub's web features directly to developers' terminals, supporting automation through scripting and integration with CI/CD pipelines. Unlike Git (which manages version control), GitHub CLI specifically handles GitHub platform features — issues, PRs, releases, gists, actions, and API access — while seamlessly integrating with Git workflows to provide a complete development experience from the terminal.
What This Cheat Sheet Covers
This topic spans 18 focused tables and 179 indexed concepts, 104 flashcards. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
A jump-to index of every table row in this cheat sheet.
An interactive map of every table and concept in this topic.
Table 1: Installation and Authentication
Everything in gh starts with proving who you are. These commands cover the full lifecycle of an authenticated session — signing in through the browser or a token, checking which account is active, juggling multiple personal and work logins, and pointing gh at GitHub Enterprise instead of github.com. The environment-variable approach is the one to remember for CI/CD, where there's no human to click through a login prompt.
| Command | Example | Description | |
|---|---|---|---|
gh auth login | • Authenticate with GitHub interactively via browser or token • prompts for GitHub.com or Enterprise • stores credentials securely | ||
gh auth status | • Display currently authenticated accounts and token scopes • shows which user is logged in • useful for verifying authentication state | ||
gh auth token | • Print the authentication token for the active account • outputs token to stdout • useful for scripting or debugging | ||
gh auth refresh -s project | • Add additional OAuth scopes to existing token • re-authenticates to request expanded permissions • required for projects, gists, or codespaces | ||
gh auth switch | • Switch between multiple authenticated accounts interactively • useful for managing personal + work accounts | ||
gh auth logout | • Remove authentication credentials from the system • prompts to select which account to remove • clears stored tokens | ||
gh auth setup-git | • Configure Git to use gh as credential helper • enables git push/pull without separate auth• automatically applied during gh auth login | ||
export GITHUB_TOKEN=ghp_... | • Authenticate using environment variable for automation • bypasses interactive login • useful in CI/CD pipelines | ||
gh auth login --hostname ghe.example.com | • Authenticate with GitHub Enterprise Server • supports version 2.20+ • use GH_HOST environment variable to set default |