| name | gh-cli |
| description | Manage GitHub via CLI including pull requests, issues, workflows, actions, releases, and repositories. Use when working with GitHub, gh commands, GitHub Actions CI/CD, PRs, issues, releases, or repository management. |
GitHub CLI
Manage GitHub resources using the gh command-line tool.
CLI Version: 2.65.0+
Prerequisites
brew install gh
sudo apt install gh
winget install GitHub.cli
conda install -c conda-forge gh
gh --version
Authentication
Two methods: interactive browser login or token-based for CI/CD.
Interactive Login
gh auth login
gh auth login --hostname github.example.com
gh auth login --git-protocol ssh
Token-Based (CI/CD, automation)
echo $MY_TOKEN | gh auth login --with-token
export GH_TOKEN=$MY_TOKEN
export GITHUB_TOKEN=$MY_TOKEN
Verify and Manage Auth
gh auth status
gh auth switch
gh auth refresh --scopes repo,read:org
gh repo set-default OWNER/REPO
gh auth logout
CLI Structure
gh pr create | list | view | merge | review | checks | checkout | close | reopen | edit | ready | diff | comment
gh issue create | list | view | close | reopen | edit | comment | delete | pin | transfer | develop | lock
gh workflow list | view | run | enable | disable
gh run list | view | watch | download | rerun | cancel
gh release create | list | view | download | edit | delete | upload
gh repo create | clone | fork | view | edit | list | sync | archive | rename | delete
gh api REST and GraphQL API calls
gh label create | list | edit | delete | clone
gh secret set | list | delete (repo/org/env scopes)
gh variable set | list | get | delete (repo/org/env scopes)
gh search repos | issues | prs | code | commits
gh gist create | list | view | edit | delete | clone
gh codespace create | list | code | ssh | stop | delete
gh extension install | list | upgrade | remove
gh alias set | list | delete
gh config set | get | list
gh status Cross-repo dashboard
Pull Requests
Create PR
gh pr create --title "Feature: new login flow" --body "Description here"
gh pr create \
--title "Feature: new login flow" \
--draft \
--reviewer user1,user2 \
--assignee @me \
--label "enhancement" \
--milestone "v2.0"
gh pr create --fill
gh pr create --base main --head feature/login --title "Login feature"
List and View PRs
gh pr list
gh pr list --state merged --author @me --limit 10
gh pr list --label "bug" --base main
gh pr view 123
gh pr view 123 --web
gh pr view 123 --json title,state,reviews
gh pr diff 123
gh pr checks 123
gh pr checks 123 --watch
Merge PR
gh pr merge 123
gh pr merge 123 --squash
gh pr merge 123 --rebase
gh pr merge 123 --squash --delete-branch --body "Squash commit message"
gh pr merge 123 --auto --squash
Review PR
gh pr review 123 --approve
gh pr review 123 --request-changes --body "Please fix the error handling"
gh pr review 123 --comment --body "Looks good overall, minor suggestions"
Checkout and Edit PR
gh pr checkout 123
gh pr ready 123
gh pr edit 123 --title "Updated title" --add-label "priority" --add-reviewer user3
gh pr close 123
gh pr reopen 123
Issues
Create Issue
gh issue create --title "Bug: login fails on Safari" --body "Steps to reproduce..."
gh issue create \
--title "Feature request: dark mode" \
--label "enhancement","ui" \
--assignee user1,user2 \
--milestone "v2.0" \
--project "Roadmap"
List and View Issues
gh issue list
gh issue list --state closed --label "bug" --assignee @me --limit 20
gh issue list --milestone "v2.0" --state all
gh issue view 456
gh issue view 456 --web
gh issue view 456 --json title,state,labels,comments
Update Issues
gh issue close 456
gh issue close 456 --reason "not planned"
gh issue reopen 456
gh issue edit 456 --title "Updated title" --add-label "priority" --remove-label "triage"
gh issue edit 456 --assignee user1 --milestone "v3.0"
gh issue comment 456 --body "Working on this now"
Workflows & Actions
List and View Workflows
gh workflow list
gh workflow view {workflow-name}
gh workflow view {workflow-name} --web
Run Workflow
gh workflow run {workflow-file} --ref main
gh workflow run deploy.yml -f environment=staging -f version=1.2.3
gh workflow run ci.yml --ref feature/new-feature
View and Monitor Runs
gh run list --limit 10
gh run list --workflow ci.yml --branch main --status failure
gh run view {run-id}
gh run view {run-id} --web
gh run view {run-id} --log
gh run view {run-id} --log-failed
gh run watch {run-id}
gh run watch {run-id} --exit-status
Manage Runs
gh run download {run-id}
gh run download {run-id} --name "build-output"
gh run download {run-id} --dir ./artifacts
gh run rerun {run-id}
gh run rerun {run-id} --failed
gh run rerun {run-id} --debug
gh run cancel {run-id}
Releases
Create Release
gh release create v1.0.0 --title "Release v1.0.0" --notes "Release notes here"
gh release create v1.0.0 --generate-notes
gh release create v1.0.0 --draft --generate-notes
gh release create v1.0.0-beta.1 --prerelease --generate-notes
gh release create v1.0.0 ./dist/*.tar.gz ./dist/*.zip --generate-notes
gh release create v1.0.0 --notes-file CHANGELOG.md
List, View, and Download
gh release list --limit 10
gh release view v1.0.0
gh release view v1.0.0 --web
gh release download v1.0.0
gh release download v1.0.0 --pattern "*.tar.gz" --dir ./downloads
Repositories
gh repo clone OWNER/REPO
gh repo clone OWNER/REPO -- --depth 1
gh repo fork OWNER/REPO
gh repo fork OWNER/REPO --clone
gh repo create my-project --public --clone
gh repo create my-project --private --add-readme --license mit --gitignore Node
gh repo view OWNER/REPO
gh repo view OWNER/REPO --web
gh repo view --json name,description,defaultBranchRef
gh repo edit --description "New description"
gh repo edit --visibility private
gh repo edit --enable-wiki=false --enable-issues=true
gh repo sync OWNER/REPO
gh repo list OWNER --limit 20 --language go --visibility public
Output Formats & JSON Queries
JSON Field Selection
gh pr list --json number,title,state,author
gh issue view 456 --json title,labels,assignees
gh pr list --json
JQ Filtering
gh pr list --json number,title,author --jq '.[].title'
gh pr list --json number,title,labels --jq '.[] | select(.labels[].name == "bug")'
gh issue list --json number,title --jq '.[] | "\(.number): \(.title)"'
Go Templates
gh pr list --json number,title --template '{{range .}}#{{.number}} {{.title}}{{"\n"}}{{end}}'
Common Parameters
| Parameter | Description |
|---|
--repo / -R | Target repo as OWNER/REPO (overrides current directory) |
--json | Select output fields (comma-separated) |
--jq | Filter JSON output with jq expression |
--template | Format output with Go template |
--web / -w | Open in web browser |
--limit / -L | Maximum number of items to return |
--state | Filter by state (open, closed, merged, all) |
--label | Filter by label |
--assignee | Filter by assignee |
--milestone | Filter by milestone |
--author | Filter by author |
Common Workflows
Create PR from current branch
BRANCH=$(git branch --show-current)
gh pr create \
--title "$(git log -1 --pretty=%s)" \
--body "$(git log -1 --pretty=%b)" \
--head "$BRANCH" \
--base main
Review and merge PR
gh pr review 123 --approve
gh pr merge 123 --squash --delete-branch
Trigger workflow and wait for result
gh workflow run deploy.yml -f environment=staging
RUN_ID=$(gh run list --workflow deploy.yml --limit 1 --json databaseId --jq '.[0].databaseId')
gh run watch "$RUN_ID" --exit-status
Create release from latest tag
TAG=$(git describe --tags --abbrev=0)
gh release create "$TAG" --generate-notes
Download latest CI artifacts
RUN_ID=$(gh run list --workflow ci.yml --status success --limit 1 --json databaseId --jq '.[0].databaseId')
gh run download "$RUN_ID" --name "build-output" --dir ./artifacts
Triage issues by label
gh issue list --label "" --limit 50 --json number,title --jq '.[].number' | while read -r num; do
gh issue edit "$num" --add-label "needs-triage"
done
References
For complete command details beyond the common operations above:
- Actions, secrets, and variables — Workflow management, secrets, variables, cache, artifact patterns, CI scripting
- Issues and labels — Issue templates, pin/transfer/develop, label CRUD, search, bulk operations
- Repos and releases — Repo creation/settings, deploy keys, rulesets, release asset management
- API, search, and advanced patterns — REST/GraphQL API, search commands, extensions, aliases, gists, codespaces, scripting patterns