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

Display installed GitHub CLI version and build info.

Open help for gh

Show top-level help and available command groups.

bashANYhelpreference
bash
gh help

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

Open detailed help for a specific subcommand.

Authenticate interactively

Authenticate with GitHub using the default browser-based flow.

bashANYauthlogin
bash
gh auth login

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

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

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

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

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"

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

Show the current editor configured for gh.

List config values

Display CLI configuration values.

bashANYconfig
bash
gh config list

Display CLI configuration values.

Show current status

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

bashANYstatusdashboard
bash
gh status

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

Open current repo in browser

Open the current repository in the browser.

bashANYbrowseweb
bash
gh browse

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

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

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

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}"

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}}"

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

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

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}"

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

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

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"

Search repositories with qualifiers.

Search code

Search code across repositories.

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

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"

Search across issues and pull requests.

Search commits

Search commits on GitHub.

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

Search commits on GitHub.

Search users

Search GitHub users.

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

Search GitHub users.

List repos for an owner

List repositories for a user or organization.

bashANYrepolist
bash
gh repo list cli --limit 50

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

Filter listed repos by language.

List labels

Show labels in the current repository.

bashANYlabelrepo
bash
gh label list

Show labels in the current repository.

List rulesets

List branch and repository rulesets.

bashANYrulesetgovernance
bash
gh ruleset list

List branch and repository rulesets.

Recommended next

No recommendations yet.