| disable-model-invocation | false |
| name | cli-gh |
| user-invocable | false |
| description | Use for GitHub CLI automation: gh commands, repo info, workflow triggers, GitHub search, codespaces, PR status, issues, repo browsing, or command-line GitHub tasks. |
GitHub CLI (gh)
Overview
Expert guidance for GitHub CLI (gh) operations and workflows. Use this skill for command-line GitHub operations including pull request management, issue tracking, repository operations, workflow automation, and codespace management.
Key capabilities:
- Create and manage pull requests from the terminal
- Track and organize issues efficiently
- Search across all of GitHub (repos, issues, PRs)
- Manage labels and project organization
- Trigger and monitor GitHub Actions workflows
- Work with codespaces
- Automate repository operations and releases
- Browse repositories, PRs, and files in the browser
Safety Rules
CRITICAL: This skill NEVER uses destructive gh CLI operations.
This skill focuses exclusively on safe, read-only, or reversible GitHub operations. The following commands are PROHIBITED and must NEVER be used:
Permanently destructive commands:
gh repo delete - Repository deletion
gh repo archive - Repository archival
gh release delete - Release deletion
gh release delete-asset - Asset deletion
gh run delete - Workflow run deletion
gh cache delete - Cache deletion
gh secret delete - Secret deletion
gh variable delete - Variable deletion
gh label delete - Label deletion
gh ssh-key delete - SSH key deletion (can lock out users)
gh gpg-key delete - GPG key deletion
gh codespace delete - Codespace deletion
gh extension remove - Extension removal
gh gist delete - Gist deletion
- Bulk deletion operations using
xargs with any destructive commands
- Shell commands:
rm -rf (except for temporary file cleanup)
Allowed operations:
- Creating resources (PRs, issues, releases, labels, repos)
- Viewing and listing (status, logs, information, searches)
- Updating and editing existing resources
- Closing PRs/issues (reversible - can be reopened)
- Reverting pull requests (creates a new revert PR)
- Canceling workflow runs (stops execution without deleting data)
- Merging pull requests (after proper review)
- Read-only git operations (
git status, git log, git diff)
Installation & Setup
gh auth login
gh auth login --clipboard
gh auth status
gh auth status --json
gh auth setup-git
Pull Requests
Creating PRs
gh pr create
gh pr create --title "Add feature" --body "Description"
gh pr create --base main --head feature-branch
gh pr create --draft
gh pr create --fill
gh pr create --reviewer @copilot
Viewing PRs
gh pr list
gh pr list --author @me
gh pr view 123
gh pr view 123 --web
gh pr diff 123
gh pr diff 123 --exclude "*.lock"
gh pr status
Managing PRs
gh pr checkout 123
gh pr review 123 --approve
gh pr review 123 --comment --body "Looks good!"
gh pr review 123 --request-changes --body "Please fix X"
gh pr edit 123 --add-reviewer @copilot
gh pr merge 123
gh pr merge 123 --squash
gh pr merge 123 --rebase
gh pr merge 123 --merge
gh pr close 123
gh pr reopen 123
gh pr ready 123
gh pr update-branch 123
gh pr revert 123
PR Checks
gh pr checks 123
gh pr checks 123 --watch
Issues
Creating Issues
gh issue create
gh issue create --title "Bug report" --body "Description"
gh issue create --template "Bug Report"
gh issue create --title "Bug" --label bug,critical
gh issue create --title "Task" --assignee @me
gh issue create --type Bug
--template cannot be combined with --body or --body-file; use it with prompts, --editor, or --web. For YAML issue forms, fetch and render the form fields yourself for non-interactive automation, or finish in the browser.
Viewing Issues
gh issue list
gh issue list --assignee @me
gh issue list --label bug
gh issue list --type Bug
gh issue list --search "is:open label:bug sort:created-desc"
gh issue view 456
gh issue view 456 --web
Managing Issues
gh issue close 456
gh issue close 123 --duplicate-of 456
gh issue reopen 456
gh issue edit 456 --title "New title"
gh issue edit 456 --add-label bug
gh issue edit 456 --add-assignee @user
gh issue comment 456 --body "Update"
gh issue develop 456 --checkout
Issue Types, Sub-Issues & Relationships
Issue types and sub-issues require GitHub.com or GHES 3.17+; blocking relationships require GHES 3.19+.
gh issue edit 456 --type Bug
gh issue edit 456 --remove-type
gh issue create --parent 100
gh issue edit 100 --add-sub-issue 123,124
gh issue edit 100 --remove-sub-issue 123
gh issue edit 123 --parent 100
gh issue edit 123 --remove-parent
gh issue create --blocked-by 200,201 --blocking 300
gh issue edit 123 --add-blocked-by 200 --add-blocking 300,301
gh issue edit 123 --remove-blocked-by 200 --remove-blocking 301
Discussions
When the user asks to list, view, create, edit, or comment on GitHub Discussions, see references/discussions.md. The gh discussion command set is in preview and subject to change.
Copilot Agent Tasks
Delegate work to the Copilot coding agent and track its sessions. The gh agent-task command set (aliases gh agent, gh agents) is in preview.
gh agent-task create "Improve the performance of the data processing pipeline"
gh agent-task list
gh agent-task list --json id,name,state
gh agent-task view 123
gh agent-task view <session-id> --json state --jq '.state'
Agent Skills
Discover, install, and publish agent skills from GitHub repositories. The gh skill command set (alias gh skills) is in preview.
gh skill search terraform
gh skill preview github/awesome-copilot documentation-writer
gh skill install github/awesome-copilot documentation-writer
gh skill install owner/repo skill-name --scope user --pin v1.2.0
gh skill install owner/repo skill-name --allow-hidden-dirs
gh skill list
gh skill update --all
gh skill publish --dry-run
Repository Operations
Repository Info
gh repo view
gh repo view --web
gh repo clone owner/repo
gh repo clone owner/repo --no-upstream
gh repo fork owner/repo
gh repo list owner
Repository Management
gh repo create my-repo --public
gh repo create my-repo --private
gh repo sync owner/repo
gh repo set-default
gh repo edit --squash-merge-commit-message COMMIT_MESSAGES
Reading Repo Contents
Read files and directories without cloning. The gh repo read-file and gh repo read-dir commands are in preview and subject to change.
gh repo read-file README.md --repo cli/cli
gh repo read-file go.mod --ref v2.94.0 --repo cli/cli
gh repo read-file README.md --output ./README.md --clobber
gh repo read-file script.sh --allow-escape-sequences
gh repo read-dir script --repo cli/cli
gh repo read-dir docs --repo cli/cli --json name,path,type,size
Search
When the user asks to search GitHub repositories, issues, or pull requests, see references/search.md.
Labels
When the user asks to list, create, edit, or clone repository labels, see references/labels.md.
Codespaces
When the user asks to list, create, connect to, or manage files within GitHub Codespaces, see references/codespaces.md.
Browse
Open repositories, files, and resources in the browser.
gh browse
gh browse src/main.go
gh browse src/main.go:42
gh browse --blame src/main.go
gh browse --actions
gh browse --branch feature
Releases
When the user asks to create, list, view, or download GitHub releases, see references/releases.md.
Gists
When the user asks to create, list, view, or edit GitHub gists, see references/gists.md.
Configuration
gh config set editor vim
gh config set git_protocol ssh
gh config list
gh config set browser firefox
Quick Reference
Common gh operations at a glance:
| Operation | Command | Common Flags |
|---|
| Create PR | gh pr create | --draft, --fill, --reviewer @copilot |
| List PRs | gh pr list | --author @me, --label, --search |
| View PR | gh pr view <number> | --web, --comments |
| Merge PR | gh pr merge <number> | --squash, --rebase, --delete-branch |
| Revert PR | gh pr revert <number> | --body |
| Create issue | gh issue create | --title, --body, --template, --type |
| List issues | gh issue list | --assignee @me, --label, --type |
| Close issue | gh issue close <number> | --duplicate-of, --reason |
| View issue | gh issue view <number> | --web, --comments |
| Link sub-issue | gh issue edit <number> | --parent, --add-sub-issue |
| Block issue | gh issue edit <number> | --add-blocked-by, --add-blocking |
| List discussions | gh discussion list | --answered, --sort, --json |
| Create agent task | gh agent-task create | --json (on list/view) |
| Install skill | gh skill install | --scope, --pin, --allow-hidden-dirs |
| Browse repo | gh browse | --blame, --actions, --branch |
| Clone repo | gh repo clone <repo> | --no-upstream |
| Fork repo | gh repo fork | --clone, --remote |
| View repo | gh repo view | --web |
| Read repo file | gh repo read-file <path> | --ref, --output, --clobber, --json |
| Read repo dir | gh repo read-dir [path] | --ref, --json |
| Create release | gh release create <tag> | --title, --notes, --draft |
| Verify release | gh release verify <tag> | --repo |
| Run workflow | gh workflow run <name> | --ref, --field |
| Watch run | gh run watch <id> | --exit-status |
| Search repos | gh search repos <query> | --language, --stars |
| Create label | gh label create <name> | --color, --description |
| Create codespace | gh codespace create | --repo, --branch |
Additional Resources
Reference Guides
For detailed patterns and advanced usage, see:
- Discussions - List, view, create, edit, and comment on GitHub Discussions (preview)
- Workflows & Actions - GitHub Actions workflows, runs, cache management, and CI/CD integration patterns
- Advanced Features - Aliases, API access, extensions, secrets, SSH/GPG keys, organizations, projects, and advanced scripting
- Automation Workflows - Common automation patterns, daily reports, release automation, and team collaboration workflows
- Troubleshooting - Solutions for authentication, permissions, rate limiting, and common errors
Example Scripts
Practical automation scripts (see examples/ directory):
auto-pr-create.sh - Automated PR creation workflow
issue-triage.sh - Bulk issue labeling and assignment
workflow-monitor.sh - Watch and notify on workflow completion
release-automation.sh - Complete release workflow automation
External Documentation
JSON Output
When the user wants to use --json flags or needs the correct gh CLI JSON field names, see references/json-output.md.
Tips
- Use
--web flag to open items in browser for detailed view
- Leverage interactive prompts by omitting parameters - most commands support interactive mode
- Apply filters with
--author, --label, --state to narrow down lists efficiently
- Add
--json flag to enable scriptable output for automation
- Always check
--help for valid JSON field names - they differ from GitHub API
- Use
gh repo create --template to scaffold from template repositories
- Enable auto-merge with
gh pr merge --auto for PRs that pass checks