gh CLI cheat sheet
Status: 🟩 COMPLETE (🟦 LIVING — gh CLI updates frequently) Last updated: 2026-06-21 Plain-English tagline: Daily-use
gh(GitHub CLI) commands grouped by intent. For the why, read GitHub.
Setup (once per machine)
# Install (Windows via winget)
winget install --id GitHub.cli
# Install (Mac via Homebrew)
brew install gh
# Authenticate (interactive browser flow)
gh auth login
# Verify
gh auth status
gh api user --jq .login # prints your GitHub usernameAfter gh auth login, Git itself can use gh’s credentials too (no PAT needed for HTTPS pushes).
Repos
gh repo create # interactive: new repo from current dir
gh repo create my-app --private --source=. --remote=origin # all-in-one
gh repo clone u/r # clone (no need for full URL)
gh repo view # view repo info in terminal
gh repo view --web # open in browser
gh repo fork u/r # fork to your account
gh repo list u # list a user's public repos
gh repo delete u/r --yes # delete (irreversible — be careful)Pull requests
gh pr create # interactive (uses your branch)
gh pr create --title "Add X" --body "..." # non-interactive
gh pr list # open PRs in current repo
gh pr list --author "@me" # only yours
gh pr view 123 # view PR #123 in terminal
gh pr view 123 --web # open #123 in browser
gh pr checkout 123 # check out PR #123 locally
gh pr diff 123 # show the diff
gh pr review 123 --approve # approve
gh pr review 123 --request-changes -b "Please fix Y" # request changes
gh pr review 123 --comment -b "Looks good but..." # comment-only review
gh pr merge 123 --squash # squash + merge
gh pr merge 123 --squash --delete-branch # squash + merge + delete branch
gh pr close 123 # close without merging
gh pr ready 123 # mark a draft as readyCommon one-liner for PR creation with a heredoc body:
gh pr create --title "Add dark mode" --body "$(cat <<'EOF'
## Summary
Add a dark/light mode toggle to the navbar.
## How to test
1. Open the app
2. Click the moon icon
3. Reload — preference persists
EOF
)"Issues
gh issue create --title "Login broken" --body "Steps: ..." # create
gh issue list # list open issues
gh issue list --assignee "@me" # assigned to you
gh issue view 42 # view #42 in terminal
gh issue view 42 --web # open in browser
gh issue close 42 # close
gh issue reopen 42 # reopen
gh issue comment 42 -b "Update: ..." # commentCI / Actions / checks
gh run list # recent workflow runs
gh run watch # follow the latest run live
gh run view <run-id> # inspect a specific run
gh run view <run-id> --log # full logs
gh run rerun <run-id> # rerun a failed workflow
gh workflow list # workflows in the repo
gh workflow run <name> # trigger a workflow manuallygh pr checks 123 shows the status of all checks on a specific PR — useful before merging.
Releases
gh release list # list releases
gh release create v1.0.0 --title "v1.0.0" --notes "..." # create a release
gh release upload v1.0.0 ./dist.zip # attach binary
gh release view v1.0.0 # view in terminal
gh release delete v1.0.0 --yes # deleteSecrets (repo + environment)
gh secret list # list (names only — values are write-only)
gh secret set SUPABASE_SERVICE_ROLE_KEY # prompts for value
gh secret set SUPABASE_KEY --body "$VALUE" # pipe a value
gh secret set SUPABASE_KEY --env production # set for an environment
gh secret remove SUPABASE_KEY # deleteGist (quick code snippets)
gh gist create file.ts --public # share a file as a public gist
gh gist create --public --filename "demo.js" - # paste from stdin
gh gist list # your gists
gh gist view <id> # view
gh gist edit <id> # edit in your editorRaw API (when there’s no first-class command)
gh api repos/owner/repo # GET
gh api repos/owner/repo/pulls/123/comments # PR comments
gh api repos/owner/repo/contents/path/to/file.md # file contents
gh api --method POST repos/owner/repo/issues/42/labels -f labels[]=bug # mutateThe gh api command speaks the full GitHub REST API. Useful for things the CLI hasn’t wrapped yet.
Common workflows
Open a PR for the branch you just pushed
git push -u origin feature/x
gh pr create --title "..." --body "..."
gh pr view --web # double-check in browserWatch a PR’s CI until it passes
gh pr checks 123 --watch # blocks until checks resolve
gh pr merge 123 --squash --delete-branch # once greenQuick triage: what PRs need my attention?
gh pr list --search "review-requested:@me" # awaiting your review
gh pr list --author "@me" --state open # your open PRsLook at all comments on a PR
gh api repos/owner/repo/pulls/123/comments # review-comment (per-line) comments
gh pr view 123 --comments # general PR commentsCommon gotchas
gh auth logindoesn’t grantgh repo deleteby default. You may need to re-rungh auth loginand grant thedelete_reposcope explicitly.gh pr merge --squashuses the PR description as the commit body. Write it well — that’s what lands onmain.gh pr checkout 123switches your local branch. Make sure your work is committed/stashed first.gh secret listshows names only. You can’t read values back via the CLI (this is intentional — secrets are write-only).gh release createwon’t auto-tag without--target. If you haven’t pushed a tag, pass--target <commit>and gh will create the tag for you.- Rate limits hit faster on
gh api. The CLI shares your account’s API quota; heavy scripting can exhaust it. gh apireturns JSON. Pipe through--jq '.field'to extract specific fields withoutjqinstalled.gh repo createdefaults to public unless you pass--private. Sets the visibility, then you can change later — but never forget the flag when you mean private.gh pr createfrom a fork needs--head <fork>:<branch>. Inside your own repo, no special syntax.- The CLI follows your default branch. If your repo’s default is
main, gh expectsmain. Setting it viagh repo edit --default-branch masteris rarely what you want.
See also
- GitHub 🟩 🟦 — the textbook
- Pull requests 🟩
- Git basics 🟩
- Git cheat sheet 🟩 — for branch/commit operations
- Common errors: Git errors 🟩
- How-to: Rescue a broken Git branch 🟩