github
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitHub Skill
GitHub 操作技能
Use the CLI to interact with GitHub repositories, issues, PRs, and CI.
gh使用 CLI与GitHub仓库、议题(Issues)、拉取请求(PRs)和CI进行交互。
ghWhen to Use
适用场景
✅ USE this skill when:
- Checking PR status, reviews, or merge readiness
- Viewing CI/workflow run status and logs
- Creating, closing, or commenting on issues
- Creating or merging pull requests
- Querying GitHub API for repository data
- Listing repos, releases, or collaborators
✅ 适用场景:
- 查看PR状态、评审情况或合并就绪状态
- 查看CI/工作流运行状态及日志
- 创建、关闭议题或在议题下评论
- 创建或合并拉取请求
- 查询GitHub API获取仓库数据
- 列出仓库、版本发布或协作者
When NOT to Use
不适用场景
❌ DON'T use this skill when:
- Local git operations (commit, push, pull, branch) → use directly
git - Non-GitHub repos (GitLab, Bitbucket, self-hosted) → different CLIs
- Cloning repositories → use
git clone - Reviewing actual code changes → use skill
coding-agent - Complex multi-file diffs → use or read files directly
coding-agent
❌ 不适用场景:
- 本地Git操作(提交、推送、拉取、分支)→ 直接使用
git - 非GitHub仓库(GitLab、Bitbucket、自建仓库)→ 使用对应CLI工具
- 克隆仓库 → 使用
git clone - 查看实际代码变更 → 使用技能
coding-agent - 复杂多文件差异对比 → 使用或直接读取文件
coding-agent
Setup
配置步骤
bash
undefinedbash
undefinedAuthenticate (one-time)
认证(仅需一次)
gh auth login
gh auth login
Verify
验证
gh auth status
undefinedgh auth status
undefinedCommon Commands
常用命令
Pull Requests
拉取请求(PR)
bash
undefinedbash
undefinedList PRs
列出所有PR
gh pr list --repo owner/repo
gh pr list --repo owner/repo
Check CI status
查看CI状态
gh pr checks 55 --repo owner/repo
gh pr checks 55 --repo owner/repo
View PR details
查看PR详情
gh pr view 55 --repo owner/repo
gh pr view 55 --repo owner/repo
Create PR
创建PR
gh pr create --title "feat: add feature" --body "Description"
gh pr create --title "feat: add feature" --body "Description"
Merge PR
合并PR
gh pr merge 55 --squash --repo owner/repo
undefinedgh pr merge 55 --squash --repo owner/repo
undefinedIssues
议题(Issues)
bash
undefinedbash
undefinedList issues
列出所有议题
gh issue list --repo owner/repo --state open
gh issue list --repo owner/repo --state open
Create issue
创建议题
gh issue create --title "Bug: something broken" --body "Details..."
gh issue create --title "Bug: something broken" --body "Details..."
Close issue
关闭议题
gh issue close 42 --repo owner/repo
undefinedgh issue close 42 --repo owner/repo
undefinedCI/Workflow Runs
CI/工作流运行
bash
undefinedbash
undefinedList recent runs
列出最近的运行记录
gh run list --repo owner/repo --limit 10
gh run list --repo owner/repo --limit 10
View specific run
查看指定运行记录
gh run view <run-id> --repo owner/repo
gh run view <run-id> --repo owner/repo
View failed step logs only
仅查看失败步骤的日志
gh run view <run-id> --repo owner/repo --log-failed
gh run view <run-id> --repo owner/repo --log-failed
Re-run failed jobs
重新运行失败的任务
gh run rerun <run-id> --failed --repo owner/repo
undefinedgh run rerun <run-id> --failed --repo owner/repo
undefinedAPI Queries
API查询
bash
undefinedbash
undefinedGet PR with specific fields
获取包含指定字段的PR信息
gh api repos/owner/repo/pulls/55 --jq '.title, .state, .user.login'
gh api repos/owner/repo/pulls/55 --jq '.title, .state, .user.login'
List all labels
列出所有标签
gh api repos/owner/repo/labels --jq '.[].name'
gh api repos/owner/repo/labels --jq '.[].name'
Get repo stats
获取仓库统计数据
gh api repos/owner/repo --jq '{stars: .stargazers_count, forks: .forks_count}'
undefinedgh api repos/owner/repo --jq '{stars: .stargazers_count, forks: .forks_count}'
undefinedJSON Output
JSON输出格式
Most commands support for structured output with filtering:
--json--jqbash
gh issue list --repo owner/repo --json number,title --jq '.[] | "\(.number): \(.title)"'
gh pr list --json number,title,state,mergeable --jq '.[] | select(.mergeable == "MERGEABLE")'大多数命令支持参数以生成结构化输出,并可通过进行过滤:
--json--jqbash
gh issue list --repo owner/repo --json number,title --jq '.[] | "\(.number): \(.title)"'
gh pr list --json number,title,state,mergeable --jq '.[] | select(.mergeable == "MERGEABLE")'Templates
模板示例
PR Review Summary
PR评审总结
bash
undefinedbash
undefinedGet PR overview for review
获取PR概览用于评审
PR=55 REPO=owner/repo
echo "## PR #$PR Summary"
gh pr view $PR --repo $REPO --json title,body,author,additions,deletions,changedFiles
--jq '"(.title) by @(.author.login)\n\n(.body)\n\n📊 +(.additions) -(.deletions) across (.changedFiles) files"' gh pr checks $PR --repo $REPO
--jq '"(.title) by @(.author.login)\n\n(.body)\n\n📊 +(.additions) -(.deletions) across (.changedFiles) files"' gh pr checks $PR --repo $REPO
undefinedPR=55 REPO=owner/repo
echo "## PR #$PR 总结"
gh pr view $PR --repo $REPO --json title,body,author,additions,deletions,changedFiles
--jq '"(.title) by @(.author.login)\n\n(.body)\n\n📊 +(.additions) -(.deletions) across (.changedFiles) files"' gh pr checks $PR --repo $REPO
--jq '"(.title) by @(.author.login)\n\n(.body)\n\n📊 +(.additions) -(.deletions) across (.changedFiles) files"' gh pr checks $PR --repo $REPO
undefinedIssue Triage
议题分类处理
bash
undefinedbash
undefinedQuick issue triage view
快速查看待分类议题
gh issue list --repo owner/repo --state open --json number,title,labels,createdAt
--jq '.[] | "[(.number)] (.title) - ([.labels[].name] | join(", ")) ((.createdAt[:10]))"'
--jq '.[] | "[(.number)] (.title) - ([.labels[].name] | join(", ")) ((.createdAt[:10]))"'
undefinedgh issue list --repo owner/repo --state open --json number,title,labels,createdAt
--jq '.[] | "[(.number)] (.title) - ([.labels[].name] | join(", ")) ((.createdAt[:10]))"'
--jq '.[] | "[(.number)] (.title) - ([.labels[].name] | join(", ")) ((.createdAt[:10]))"'
undefinedNotes
注意事项
- Always specify when not in a git directory
--repo owner/repo - Use URLs directly:
gh pr view https://github.com/owner/repo/pull/55 - Rate limits apply; use for repeated queries
gh api --cache 1h
- 当不在Git目录下时,务必指定参数
--repo owner/repo - 可直接使用URL:
gh pr view https://github.com/owner/repo/pull/55 - 存在调用频率限制;对于重复查询,使用进行缓存
gh api --cache 1h