AgentSkillsCN

gh-reference

全面的 GitHub CLI(gh)命令参考。适用于处理 GitHub 的各类操作,如拉取请求、问题、仓库、发布、工作流、Actions 运行、Secrets、标签、Gist,或 GitHub API。涵盖所有 gh 命令、子命令、标志及常见模式。

SKILL.md
--- frontmatter
name: gh-reference
description: Comprehensive reference for the GitHub CLI (gh) command. Use when working with GitHub operations like pull requests, issues, repos, releases, workflows, Actions runs, secrets, labels, gists, or the GitHub API. Covers all gh commands, subcommands, flags, and common patterns.
user-invocable: false

GitHub CLI (gh) Complete Reference

You have access to the gh CLI for all GitHub operations. This skill provides a comprehensive reference for every command, flag, and common usage pattern.

Quick Command Map

TaskCommand
Create PRgh pr create --title "..." --body "..."
List PRsgh pr list
View PRgh pr view <number>
Merge PRgh pr merge <number> --squash --delete-branch
Checkout PRgh pr checkout <number>
PR diffgh pr diff <number>
PR checksgh pr checks <number>
Create issuegh issue create --title "..." --body "..."
List issuesgh issue list
View issuegh issue view <number>
Close issuegh issue close <number>
Create releasegh release create <tag> --generate-notes
View repogh repo view
Clone repogh repo clone <owner/repo>
Raw API callgh api <endpoint>
Search codegh search code <query>
Search issuesgh search issues <query>
List runsgh run list
View rungh run view <run-id>
Trigger workflowgh workflow run <workflow>
List labelsgh label list
Create gistgh gist create <file>
Set secretgh secret set <name>
Set variablegh variable set <name>
Auth statusgh auth status
API-Only Operations
Create/edit/delete filesgh api repos/{owner}/{repo}/contents/path -X PUT ...
Create branchgh api repos/{owner}/{repo}/git/refs -f ref="refs/heads/name" ...
Delete branchgh api repos/{owner}/{repo}/git/refs/heads/name -X DELETE
Create taggh api repos/{owner}/{repo}/git/refs -f ref="refs/tags/v1.0" ...
Add reactiongh api repos/{owner}/{repo}/issues/123/reactions -f content="+1"
Manage milestonesgh api repos/{owner}/{repo}/milestones ...
Manage webhooksgh api repos/{owner}/{repo}/hooks ...
Branch protectiongh api repos/{owner}/{repo}/branches/main/protection ...
Manage collaboratorsgh api repos/{owner}/{repo}/collaborators/user ...
Notificationsgh api notifications ...
Compare branchesgh api repos/{owner}/{repo}/compare/main...feature
Repo statisticsgh api repos/{owner}/{repo}/stats/contributors
Deploymentsgh api repos/{owner}/{repo}/deployments ...
Star/unstar repogh api user/starred/owner/repo -X PUT
Repository dispatchgh api repos/{owner}/{repo}/dispatches -f event_type="..." ...
Org managementgh api orgs/{org}/members ...

Inherited Flags (Available on Most Commands)

code
--help                          Show help for command
-R, --repo [HOST/]OWNER/REPO   Select another repository

JSON Output (Available on list/view/status Commands)

code
--json <fields>       Output JSON with specified fields
-q, --jq <expr>       Filter JSON output using jq expression
-t, --template <str>  Format JSON output using Go template

Detailed References

For complete flags and parameters for each command group, see:

  • pr-reference.md - Pull request commands (create, list, view, merge, checkout, diff, review, edit, close, reopen, comment, checks, status, ready, revert, lock, unlock, update-branch)
  • issue-reference.md - Issue commands (create, list, view, edit, close, reopen, comment, delete, develop, lock, unlock, pin, unpin, transfer, status)
  • repo-reference.md - Repository commands (create, clone, fork, view, list, edit, delete, sync, rename, archive, unarchive, deploy-key, set-default)
  • advanced-reference.md - API calls, search, releases, workflow runs, Actions, secrets, variables, labels, gists, auth, and more. Also includes API-only recipes for: file operations, branch/tag management, reactions, milestones, webhooks, branch protection, collaborators, notifications, commit comments/comparisons, repo statistics, deployments, starring/watching, repository dispatch events, and organization management

Important Patterns

HEREDOC for Multi-line Bodies

Always use HEREDOC for multi-line body text to preserve formatting:

bash
gh pr create --title "Title" --body "$(cat <<'EOF'
## Summary
- Change 1
- Change 2

## Test plan
- [ ] Test A
EOF
)"

JSON Filtering with jq

bash
# Get PR titles
gh pr list --json title -q '.[].title'

# Get issue URLs
gh issue list --json url,number -q '.[] | "\(.number): \(.url)"'

# Get failed workflow runs
gh run list --json conclusion,name -q '.[] | select(.conclusion=="failure")'

Working with the API Directly

bash
# GET endpoint with placeholders
gh api repos/{owner}/{repo}/pulls

# POST with fields
gh api repos/{owner}/{repo}/issues/123/comments -f body='comment text'

# GraphQL queries
gh api graphql -f query='{ viewer { login } }'

# Paginate results
gh api repos/{owner}/{repo}/issues --paginate

Cross-Repository Operations

bash
# Any command can target a different repo with -R
gh pr list -R owner/other-repo
gh issue view 42 -R owner/other-repo

PR Review Comments via API

bash
# View comments on a PR
gh api repos/{owner}/{repo}/pulls/123/comments

# View review comments
gh api repos/{owner}/{repo}/pulls/123/reviews