GitHub CLI Cheat Sheet

Core GitHub CLI commands for auth, repository context, search, JSON output, and daily workflows.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Getting Started
Show gh version
gh --version

# Display installed GitHub CLI version and build info.

Open help for gh
gh help

# Show top-level help and available command groups.

Show help for a subcommand
gh help pr create

# Open detailed help for a specific subcommand.

Authenticate interactively
gh auth login

# Authenticate with GitHub using the default browser-based flow.

Authenticate to GitHub Enterprise
gh auth login --hostname github.example.com

# Authenticate against a GitHub Enterprise Server host.

Show auth status
gh auth status

# Show which hosts are authenticated and how credentials are stored.

Refresh auth scopes
gh auth refresh -s repo,read:org,workflow

# Refresh token scopes for an authenticated host.

Log out from a host
gh auth logout --hostname github.com

# Remove stored authentication for a host.

Set preferred editor
gh config set editor "code --wait"

# Set the editor used by gh when editing text.

Get configured editor
gh config get editor

# Show the current editor configured for gh.

List config values
gh config list

# Display CLI configuration values.

Show current status
gh status

# Show account, issue, PR, and assignment activity summary.

Open current repo in browser
gh browse

# Open the current repository in the browser.

Open current branch compare view
gh browse --branch feature/my-branch

# Open a repo page scoped to a specific branch.

Open repo in browser
gh repo view --web

# Open the selected repository in the web UI.

## Formatting and JSON Output
List PRs as JSON
gh pr list --json number,title,author,state

# Return pull request data as JSON fields.

Filter PR JSON with jq syntax
gh pr list --json number,title --jq ".[] | {number, title}"

# Post-process JSON output using the built-in jq expression support.

Format PR output with Go template
gh pr view 123 --json number,title,mergeStateStatus --template "{{.number}} {{.title}} {{.mergeStateStatus}}"

# Format JSON output using a Go template.

List issues as JSON
gh issue list --json number,title,labels,assignees

# Return issue fields as JSON for scripting.

List workflow runs as JSON
gh run list --json databaseId,workflowName,status,conclusion

# Inspect Actions runs in script-friendly JSON.

Query REST API and filter fields
gh api repos/{owner}/{repo} --jq "{default_branch,visibility,open_issues_count}"

# Call the API directly and project specific values.

Paginate API results
gh api repos/{owner}/{repo}/pulls --paginate

# Fetch all pages from a paginated REST endpoint.

Search repos as JSON
gh search repos "topic:terraform stars:>5000" --json name,owner,url,stargazersCount

# Search GitHub repositories and output structured JSON.

## Search and Discovery
Search repositories
gh search repos "language:go stars:>1000 topic:kubernetes"

# Search repositories with qualifiers.

Search code
gh search code "TODO owner:cli path:/docs extension:md"

# Search code across repositories.

Search issues and PRs
gh search issues "is:open is:pr review-requested:@me"

# Search across issues and pull requests.

Search commits
gh search commits "fix login author:octocat"

# Search commits on GitHub.

Search users
gh search users "location:California followers:>100"

# Search GitHub users.

List repos for an owner
gh repo list cli --limit 50

# List repositories for a user or organization.

List repos filtered by language
gh repo list my-org --language TypeScript --limit 100

# Filter listed repos by language.

List labels
gh label list

# Show labels in the current repository.

List rulesets
gh ruleset list

# List branch and repository rulesets.

Recommended next

No recommendations yet.