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

Install, authenticate, and inspect core CLI behavior.

Show gh version

Display installed GitHub CLI version and build info.

bashANYversioninstall
bash
gh --version
Notes

Display installed GitHub CLI version and build info.

Open help for gh

Show top-level help and available command groups.

bashANYhelpreference
bash
gh help
Notes

Show top-level help and available command groups.

Show help for a subcommand

Open detailed help for a specific subcommand.

bashANYhelpreferencepr
bash
gh help pr create
Notes

Open detailed help for a specific subcommand.

Authenticate interactively

Authenticate with GitHub using the default browser-based flow.

bashANYauthlogin
bash
gh auth login
Notes

Authenticate with GitHub using the default browser-based flow.

Authenticate to GitHub Enterprise

Authenticate against a GitHub Enterprise Server host.

bashANYauthghe
bash
gh auth login --hostname github.example.com
Notes

Authenticate against a GitHub Enterprise Server host.

Show auth status

Show which hosts are authenticated and how credentials are stored.

bashANYauthstatus
bash
gh auth status
Notes

Show which hosts are authenticated and how credentials are stored.

Refresh auth scopes

Refresh token scopes for an authenticated host.

bashANYauthscopes
bash
gh auth refresh -s repo,read:org,workflow
Notes

Refresh token scopes for an authenticated host.

Log out from a host

Remove stored authentication for a host.

bashANYauthlogout
bash
gh auth logout --hostname github.com
Notes

Remove stored authentication for a host.

Set preferred editor

Set the editor used by gh when editing text.

bashANYconfigeditor
bash
gh config set editor "code --wait"
Notes

Set the editor used by gh when editing text.

Get configured editor

Show the current editor configured for gh.

bashANYconfigeditor
bash
gh config get editor
Notes

Show the current editor configured for gh.

List config values

Display CLI configuration values.

bashANYconfig
bash
gh config list
Notes

Display CLI configuration values.

Show current status

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

bashANYstatusdashboard
bash
gh status
Notes

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

Open current repo in browser

Open the current repository in the browser.

bashANYbrowseweb
bash
gh browse
Notes

Open the current repository in the browser.

Open current branch compare view

Open a repo page scoped to a specific branch.

bashANYbrowsebranch
bash
gh browse --branch feature/my-branch
Notes

Open a repo page scoped to a specific branch.

Open repo in browser

Open the selected repository in the web UI.

bashANYrepoweb
bash
gh repo view --web
Notes

Open the selected repository in the web UI.

Formatting and JSON Output

Use JSON, jq, and templates for automation.

List PRs as JSON

Return pull request data as JSON fields.

bashANYjsonprautomation
bash
gh pr list --json number,title,author,state
Notes

Return pull request data as JSON fields.

Filter PR JSON with jq syntax

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

bashANYjsonjqpr
bash
gh pr list --json number,title --jq ".[] | {number, title}"
Notes

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

Format PR output with Go template

Format JSON output using a Go template.

bashANYtemplatepr
bash
gh pr view 123 --json number,title,mergeStateStatus --template "{{.number}} {{.title}} {{.mergeStateStatus}}"
Notes

Format JSON output using a Go template.

List issues as JSON

Return issue fields as JSON for scripting.

bashANYjsonissue
bash
gh issue list --json number,title,labels,assignees
Notes

Return issue fields as JSON for scripting.

List workflow runs as JSON

Inspect Actions runs in script-friendly JSON.

bashANYjsonactionsrun
bash
gh run list --json databaseId,workflowName,status,conclusion
Notes

Inspect Actions runs in script-friendly JSON.

Query REST API and filter fields

Call the API directly and project specific values.

bashANYapijqrest
bash
gh api repos/{owner}/{repo} --jq "{default_branch,visibility,open_issues_count}"
Notes

Call the API directly and project specific values.

Paginate API results

Fetch all pages from a paginated REST endpoint.

bashANYapipagination
bash
gh api repos/{owner}/{repo}/pulls --paginate
Notes

Fetch all pages from a paginated REST endpoint.

Search repos as JSON

Search GitHub repositories and output structured JSON.

bashANYsearchreposjson
bash
gh search repos "topic:terraform stars:>5000" --json name,owner,url,stargazersCount
Notes

Search GitHub repositories and output structured JSON.

Search and Discovery

Search repos, issues, PRs, and code across GitHub.

Search repositories

Search repositories with qualifiers.

bashANYsearchrepos
bash
gh search repos "language:go stars:>1000 topic:kubernetes"
Notes

Search repositories with qualifiers.

Search code

Search code across repositories.

bashANYsearchcode
bash
gh search code "TODO owner:cli path:/docs extension:md"
Notes

Search code across repositories.

Search issues and PRs

Search across issues and pull requests.

bashANYsearchissuespr
bash
gh search issues "is:open is:pr review-requested:@me"
Notes

Search across issues and pull requests.

Search commits

Search commits on GitHub.

bashANYsearchcommits
bash
gh search commits "fix login author:octocat"
Notes

Search commits on GitHub.

Search users

Search GitHub users.

bashANYsearchusers
bash
gh search users "location:California followers:>100"
Notes

Search GitHub users.

List repos for an owner

List repositories for a user or organization.

bashANYrepolist
bash
gh repo list cli --limit 50
Notes

List repositories for a user or organization.

List repos filtered by language

Filter listed repos by language.

bashANYrepolistlanguage
bash
gh repo list my-org --language TypeScript --limit 100
Notes

Filter listed repos by language.

List labels

Show labels in the current repository.

bashANYlabelrepo
bash
gh label list
Notes

Show labels in the current repository.

List rulesets

List branch and repository rulesets.

bashANYrulesetgovernance
bash
gh ruleset list
Notes

List branch and repository rulesets.

Recommended next

No recommendations yet.