GitHub CLI
Manage pull requests, issues, repos, and workflows directly from the terminal with gh.
Search across all documentation pages
Manage pull requests, issues, repos, and workflows directly from the terminal with gh.
🤖 Read the SystemsArchitect.io Blog for over 100+ cloud architecture articles 🔥
Quick-reference recipe card - copy-paste ready.
# Authenticate
gh auth login
# Create a pull request
gh pr create --title "feat: add auth page" --body "Adds login and signup forms"
# List open PRs
gh pr list
# Check out a PR locally
gh pr checkout 42
# Merge a PR
gh pr merge 42 --squash --delete-branch
# Create an issue
gh issue create --title "Bug: sidebar flickers" --label bug
# View repo in browser
gh browseWhen to reach for this: Any GitHub operation you would normally do in the browser - PRs, issues, releases, Actions.
# Full PR workflow from terminal
git checkout -b feature/search
# ... write code ...
git add src/components/Search.tsx src/app/search/page.tsx
git commit -m "feat: add search page with debounced input"
git push -u origin feature/search
# Create PR with body
gh pr create --title "feat: add search page" --body "## Summary
- Debounced search input with 300ms delay
- Server-side filtering via search params
- Loading skeleton during fetch
## Test plan
- [ ] Type in search box, verify debounce
- [ ] Check URL updates with search param
- [ ] Verify loading state appears"
# Check CI status
gh pr checks 42
# View PR diff
gh pr diff 42
# Merge when ready
gh pr merge 42 --squash --delete-branchWhat this demonstrates:
--squash combines all commits into one clean commit on main--delete-branch cleans up the remote branch after merge# Create PR (interactive - prompts for title, body, reviewers)
gh pr create
# Create PR with reviewers and labels
gh pr create --title "fix: resolve hydration error" \
--reviewer teammate1,teammate2 \
--label "bug,priority:high"
# Create draft PR
gh pr create --draft --title "WIP: new dashboard"
# List PRs with filters
gh pr list --state open --author @me
gh pr list --label "needs-review"
gh pr list --search "is:open draft:false"
# View PR details
gh pr view 42
gh pr view 42 --web # opens in browser
# Review a PR
gh pr checkout 42
gh pr review 42 --approve
gh pr review 42 --request-changes --body "Need to handle the loading state"
gh pr review 42 --comment --body "Looks good, minor suggestion on line 45"
# Merge options
gh pr merge 42 --merge # merge commit
gh pr merge 42 --squash # squash and merge
gh pr merge 42 --rebase # rebase and merge
gh pr merge 42 --auto --squash # auto-merge when checks pass
# Close without merging
gh pr close 42# Create issue (interactive)
gh issue create
# Create with labels and assignee
gh issue create \
--title "Add dark mode support" \
--body "Users have requested a dark mode toggle in settings." \
--label "enhancement,ui" \
--assignee @me
# List issues
gh issue list
gh issue list --label "bug" --state open
gh issue list --assignee @me
# View and manage
gh issue view 15
gh issue close 15
gh issue reopen 15
# Add a comment
gh issue comment 15 --body "Fixed in PR #42"
# Transfer issue to another repo
gh issue transfer 15 org/other-repo# Clone a repo
gh repo clone owner/repo
# Create a new repo
gh repo create my-app --private --clone
gh repo create my-app --public --template nextjs/template
# Fork a repo
gh repo fork owner/repo --clone
# View repo info
gh repo view
gh repo view owner/repo --web
# List your repos
gh repo list --language typescript --sort updated
# Set repo topics
gh repo edit --add-topic "nextjs,react,typescript"# List recent workflow runs
gh run list
# View a specific run
gh run view 12345
# Watch a run in progress
gh run watch 12345
# Re-run a failed job
gh run rerun 12345 --failed
# Trigger a workflow manually
gh workflow run deploy.yml --ref main
# List workflows
gh workflow list
gh workflow view deploy.yml# Create a release
gh release create v1.0.0 --title "v1.0.0" --notes "Initial release"
# Create release with auto-generated notes
gh release create v1.1.0 --generate-notes
# Create a draft release
gh release create v2.0.0-beta --draft --prerelease
# List releases
gh release list
# Download release assets
gh release download v1.0.0# Call any GitHub REST API endpoint
gh api repos/owner/repo/pulls/42/comments
# Create a comment via API
gh api repos/owner/repo/issues/15/comments \
-f body="Automated comment from CLI"
# GraphQL query
gh api graphql -f query='
query {
repository(owner: "vercel", name: "next.js") {
stargazerCount
description
}
}
'
# Paginate results
gh api repos/owner/repo/issues --paginate --jq '.[].title'Things that will bite you. Each gotcha includes what goes wrong, why it happens, and the fix.
Auth scope issues - gh returns 403 errors for certain operations. Fix: Re-authenticate with the required scopes: gh auth login --scopes repo,read:org.
Wrong default branch - PR targets the wrong base branch. Fix: Specify explicitly: gh pr create --base main.
Auto-merge not enabled - gh pr merge --auto fails silently. Fix: Enable auto-merge in the repo settings first (Settings > General > Allow auto-merge).
Stale checkout - gh pr checkout doesn't pull latest changes if you already have the branch. Fix: Run git pull after checkout, or delete the local branch first.
Other ways to solve the same problem - and when each is the better choice.
| Alternative | Use When | Don't Use When |
|---|---|---|
| GitHub web UI | Complex PR reviews with inline comments | Quick operations or scripting |
hub CLI (legacy) | Already embedded in existing scripts | New projects - gh is the official successor |
| GitHub API directly | Custom integrations or CI scripts | Interactive terminal workflows |
| VS Code GitHub extension | You prefer a GUI within your editor | Terminal-first workflows |
gh auth logingh pr create --draft --title "WIP: new feature"gh pr ready 42--squash combines all commits into one commit on the target branch--merge creates a merge commit preserving all individual commits--rebase replays commits individually on top of the target branch (linear history)gh pr checks 42gh pr checks 42 --watch to follow in real-timegh issue create --title "Bug: form validation" --assignee @me --label bug@me is a shorthand for your GitHub usernamegh api repos/owner/repo/pulls/42/comments
gh api graphql -f query='{ viewer { login } }'gh api handles authentication automaticallygh run rerun 12345 --failedgh pr checkout switches to it without pullinggit pull after checkout to get the latest changesgh pr create --base develop --title "feat: new feature"--base, the PR targets the repository's default branch (usually main)gh pr create --title "fix: type error in utils" \
--reviewer teammate1 \
--label "bug,typescript"gh pr list --state open --author @me--repo owner/repo to scope to a specific repositoryReviewed by Chris St. John·Last updated Jul 19, 2026
🤖 Read the SystemsArchitect.io Blog for over 100+ cloud architecture articles 🔥