| name | github |
| category | dev |
| description | GitHub CLI (gh) for repository management, issues, pull requests, releases, workflows, search, gists, and API access. Use when the user asks about any GitHub operation — creating repos, forking, cloning, PR workflows, issue triage, CI/CD runs, code search, release management, or direct API calls. Keywords: github, gh, pull request, issue, repository, release, workflow, actions, search, gist, fork, clone, label, milestone, project.
|
| license | MIT |
| compatibility | Requires gh (GitHub CLI) v2.0+. Install via brew install gh (macOS), winget install GitHub.cli (Windows), or apt install gh (Linux). |
| metadata | {"author":"zeph","version":"1.0"} |
GitHub CLI Operations
IMPORTANT: Always use gh CLI for ALL GitHub interactions. Never use curl with GitHub API
directly — gh api handles authentication, pagination, and rate limiting automatically.
Quick Reference
Authentication
gh auth login
echo "$TOKEN" | gh auth login --with-token
gh auth status
gh auth switch
gh auth refresh --scopes read:project
gh auth logout
Environment variable auth (overrides stored credentials):
| Variable | Purpose |
|---|
GH_TOKEN / GITHUB_TOKEN | Auth token for github.com |
GH_ENTERPRISE_TOKEN | Auth token for GitHub Enterprise |
Repository Workflows
gh repo create my-project --public --clone
gh repo create my-project --template OWNER/TEMPLATE --clone --public
gh repo fork OWNER/REPO --clone
gh repo clone OWNER/REPO
gh repo view OWNER/REPO
gh repo view OWNER/REPO --json name,description,stargazerCount
gh repo archive OWNER/REPO
gh repo delete OWNER/REPO --yes
gh repo set-default OWNER/REPO
gh repo rename NEW-NAME
Pull Request Workflow
gh pr create --title "Title" --body "Description"
gh pr create --base develop --title "Title" --body "Body"
gh pr create --draft --title "WIP: Feature" --body "Body"
gh pr list --limit 20
gh pr view 123
gh pr view 123 --json state,reviews,checks
gh pr checks 123
gh pr review 123 --approve
gh pr review 123 --request-changes --body "Fix X"
gh pr review 123 --comment --body "Looks good"
gh pr merge 123 --squash --delete-branch
gh pr merge 123 --rebase
gh pr merge 123 --merge
gh pr close 123
gh pr diff 123
gh pr checkout 123
gh pr edit 123 --add-label "bug" --add-reviewer "user"
gh pr edit 123 --milestone "v1.0"
gh api repos/OWNER/REPO/pulls/123/comments
Issue Triage
gh issue list --limit 20
gh issue list --label "bug" --assignee "@me"
gh issue list --state closed --limit 10
gh issue create --title "Bug: X" --body "Steps to reproduce..."
gh issue create --label "bug,critical" --assignee "@me"
gh issue view 456
gh issue view 456 --json title,body,labels,comments
gh issue close 456 --reason "completed"
gh issue reopen 456
gh issue edit 456 --add-label "priority:high" --milestone "v2.0"
gh issue transfer 456 OWNER/OTHER-REPO
gh issue pin 456
gh issue unpin 456
gh issue comment 456 --body "Working on this"
gh api repos/OWNER/REPO/issues/456/comments
Search
Never use curl or browser for GitHub search. Use gh search subcommands:
gh search repos "cli language:rust stars:>100" --limit 10 --sort stars
gh search code "fn parse language:rust repo:OWNER/REPO" --limit 10
gh search code "filename:Cargo.toml org:ORG" --limit 10
gh search issues "repo:OWNER/REPO is:open label:bug" --limit 10
gh search prs "is:merged author:USER" --limit 10 --sort updated
gh search commits "fix memory repo:OWNER/REPO" --limit 10 --sort committer-date
Key qualifiers: repo:, org:, language:, filename:, path:, extension:, is:,
label:, author:, stars:, created:, in:.
Full qualifier reference: references/search.md
Output Formatting
JSON output (--json)
Select specific fields to reduce output size:
gh pr list --json number,title,state
gh issue list --json number,title,labels,assignees
gh repo view --json name,description,stargazerCount
gh pr view 123 --json commits,files,reviews
JQ filtering (--jq)
Filter and transform JSON output:
gh pr list --json title --jq '.[].title'
gh issue list --json number,title,labels \
--jq '.[] | select(.labels | any(.name == "bug"))'
gh pr list --json author --jq '[.[].author.login] | group_by(.) | map({(.[0]): length}) | add'
gh pr view 123 --json reviews --jq '.reviews[].state'
Go templates (--template)
gh issue list --template '{{range .}}#{{.number}} {{.title}}{{"\n"}}{{end}}'
gh pr list --template '{{range .}}{{.number}}\t{{.state}}\t{{.title}}{{"\n"}}{{end}}'
API Access
Use gh api for any GitHub REST or GraphQL endpoint not covered by built-in commands:
gh api repos/OWNER/REPO
gh api repos/OWNER/REPO/contributors --paginate
gh api repos/OWNER/REPO/issues -f title="Bug" -f body="Description"
gh api graphql -f query='{ viewer { login } }'
gh api repos/OWNER/REPO/releases --jq '.[0].tag_name'
gh api repos/OWNER/REPO/issues --paginate --jq '.[].title'
Full API reference: references/api.md
CI/CD and Workflows
gh run list --limit 10
gh run list --workflow build.yml --limit 5
gh run view RUN_ID
gh run view RUN_ID --log
gh run watch RUN_ID
gh run rerun RUN_ID
gh run rerun RUN_ID --failed
gh workflow run build.yml --ref main
gh workflow list
gh secret set SECRET_NAME --body "value"
gh secret list
gh variable set VAR_NAME --body "value"
gh variable list
gh cache list
gh cache delete KEY
Full workflows reference: references/workflows.md
Environment Variables
| Variable | Description |
|---|
GH_TOKEN | Auth token (overrides stored credentials) |
GITHUB_TOKEN | Alternative to GH_TOKEN |
GH_ENTERPRISE_TOKEN | Token for GitHub Enterprise |
GH_HOST | Default GitHub hostname |
GH_REPO | Default repo in [HOST/]OWNER/REPO format |
GH_EDITOR | Editor for interactive commands |
GH_BROWSER | Browser for gh browse |
GH_PAGER | Pager for output (default: system pager) |
GH_DEBUG | Set to 1 or api for debug output |
GH_NO_UPDATE_NOTIFIER | Set to 1 to disable update notifications |
GH_CONFIG_DIR | Config directory (default: ~/.config/gh) |
NO_COLOR | Disable color output |
Configuration
gh config list
gh config set editor vim
gh config set git_protocol ssh
gh config set browser "firefox"
gh config set prompt disabled
gh config set git_protocol ssh --host github.example.com
Extensions
gh ext browse
gh ext install OWNER/gh-EXTENSION
gh ext list
gh ext upgrade --all
gh ext upgrade OWNER/gh-EXTENSION
gh ext remove OWNER/gh-EXTENSION
Token-Saving Patterns
- Always use
--limit N or | head -N to cap output
- Use
--json FIELD1,FIELD2 to select only needed fields
- Use
--jq 'EXPRESSION' to filter JSON responses
- Combine
--json and --jq to get minimal output in one call
- Use
gh api --paginate instead of manual pagination loops
- Use
--web to open in browser instead of fetching large content
- Prefer
gh pr checks over gh run list when checking a specific PR