| name | github-cli |
| description | GitHub CLI (gh) workflows and best practices. Use when working with PRs, issues, workflows, releases, or GitHub API. Triggers on "gh", "github cli", "create pr", "check ci", "merge pr", "copilot coding agent", etc. |
GitHub CLI
When to Use
- Creating, reviewing, or merging PRs
- Working with issues, releases, or workflows
- Querying GitHub API (prefer
gh api over raw curl)
- CI/CD debugging and monitoring
- Managing Copilot coding agent tasks
What's New (2026)
Native gh copilot Bridge (v2.86.0)
gh copilot
gh copilot <args>
Replaces the old gh-copilot extension. Now built into gh as a native command.
Copilot Coding Agent Integration (v2.80.0+)
gh agent-task create "refactor authentication module"
gh agent-task create --custom-agent my-agent "refactor auth"
gh agent-task list
gh agent-task view <task-id> --follow
PR Revert Command (v2.83.0)
gh pr revert <number>
Release Attestation Verification (v2.81.0)
gh release verify v1.2.3
gh release verify-asset v1.2.3 binary.tar.gz
Advanced Search Syntax (v2.79.0)
gh pr list --search 'review:required draft:false'
gh issue list --search 'no:assignee label:"help wanted",bug sort:created-asc'
gh pr list --search 'label:"bug" label:"urgent"'
gh pr list --search 'label:"bug","wip"'
Auth Improvements
gh auth login --clipboard
gh auth refresh --clipboard
gh auth status --json
Accessibility Preview (v2.72.0+)
gh a11y
Copilot CLI (Standalone)
The old gh-copilot extension was deprecated Oct 25, 2025. Replaced by standalone Copilot CLI + native gh copilot bridge (v2.86.0).
npm install -g @github/copilot-cli
brew install copilot-cli
copilot
gh copilot
/model
/delegate
/login
The new Copilot CLI supports custom MCP servers, custom agents (copilot --agent=my-agent), and is a full agentic assistant.
Modern Patterns
JSON Output + jq
Always use --json for scripting. Never parse human-readable output.
gh pr list --json number,title,author --jq '.[] | "\(.number): \(.title)"'
gh pr list --json number,title,state --jq '.[] | select(.state == "OPEN")'
Browse Shortcuts
gh browse
gh browse -p
gh browse -r
gh browse -s
gh browse -A
gh browse path/to/file.py:59
gh browse 123
The -w Flag (Open in Web)
Works across many commands:
gh issue list -w
gh pr view -w
gh release view -w
gh workflow view -w
gh run view -w
Issue-Linked Branches
gh issue develop -c 123
PR Creation Modes
gh pr create
gh pr create --fill
gh pr create --fill-first
gh pr create --fill-verbose
gh pr create -t "feat: thing" -b "Description here"
gh pr create -t "feat: thing" -F body.md
gh pr create -e --fill-first
gh pr create -w
gh pr create --fill -d -r @team/reviewers -l "needs-review"
PR Checkout
gh pr checkout 719
gh pr checkout https://github.com/user/repo/pull/719
gh co 719
PR Review
gh pr view 719 --comments
gh pr diff 719
gh pr diff 719 --name-only
gh api 'repos/{owner}/{repo}/pulls/719/comments' \
--jq '.[] | "\(.path):\(.line) — \(.user.login): \(.body)"'
gh api 'repos/{owner}/{repo}/issues/719/timeline' --paginate \
--jq '.[] | select(.event=="cross-referenced") | .source.issue | "\(.repository.full_name)#\(.number) — \(.title)"'
Auto-Merge Workflows
gh pr merge --auto --squash
gh pr merge -m
gh pr merge -r
gh pr merge -s
gh pr merge -d --squash
gh pr merge --disable-auto
Workflow Watching
gh run watch
gh run watch <run-id>
gh run watch --compact
gh run watch --exit-status
gh workflow run deploy.yml && sleep 2 && gh run watch
CI Debugging
gh run view <run-id> --log-failed
gh run rerun <run-id> --failed
gh run cancel <run-id> --force
gh run download <run-id>
Cache Management
gh cache list
gh cache delete <key>
gh cache delete <key> --ref refs/heads/feature-x
gh cache delete --all --succeed-on-no-caches
GraphQL API
Use for complex/nested queries where REST would require multiple calls.
gh api graphql -f query='
query($owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) {
pullRequests(first: 10, states: OPEN) {
nodes {
number
title
reviews(first: 5) { nodes { state } }
}
}
}
}
' -F owner='{owner}' -F repo='{repo}'
Attestation Verification
gh attestation verify <artifact> --owner <org>
gh attestation verify <artifact> --bundle attestation.json
Extensions
gh extension install <owner/repo>
gh extension install dlvhdr/gh-dash
gh extension install github/gh-models
gh-models (Model Evaluation)
gh models eval
gh models generate
Useful Aliases
gh alias set pv 'pr view --web'
gh alias set co 'pr checkout'
gh alias set ms 'pr merge --squash --auto'
gh alias set ww 'run watch --exit-status'
Anti-Patterns
| Avoid | Instead |
|---|
| Parsing text output | --json + --jq |
curl to GitHub API | gh api (handles auth, pagination) |
| Manual polling for CI | gh run watch |
| Multiple REST calls for nested data | GraphQL |
gh copilot extension (old) | copilot CLI or gh copilot bridge (v2.86.0+) |
| gh < v2.86 | Upgrade — native Copilot bridge, agent-task improvements |
Authentication Contexts
| Context | Method |
|---|
| Local dev | gh auth login (browser OAuth) |
| CI/Actions | GITHUB_TOKEN auto-injected |
| CI (elevated perms) | GH_TOKEN env var with PAT |
| Codespaces | Auto-authenticated |
| SSH preference | gh auth login --git-protocol ssh |
| Scope refresh | gh auth refresh --scopes write:packages |
Sources