github

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub Skill

GitHub 操作技能

Use the
gh
CLI to interact with GitHub repositories, issues, PRs, and CI.
使用
gh
CLI与GitHub仓库、议题(Issues)、拉取请求(PRs)和CI进行交互。

When 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
    git
    directly
  • Non-GitHub repos (GitLab, Bitbucket, self-hosted) → different CLIs
  • Cloning repositories → use
    git clone
  • Reviewing actual code changes → use
    coding-agent
    skill
  • Complex multi-file diffs → use
    coding-agent
    or read files directly
不适用场景:
  • 本地Git操作(提交、推送、拉取、分支)→ 直接使用
    git
  • 非GitHub仓库(GitLab、Bitbucket、自建仓库)→ 使用对应CLI工具
  • 克隆仓库 → 使用
    git clone
  • 查看实际代码变更 → 使用
    coding-agent
    技能
  • 复杂多文件差异对比 → 使用
    coding-agent
    或直接读取文件

Setup

配置步骤

bash
undefined
bash
undefined

Authenticate (one-time)

认证(仅需一次)

gh auth login
gh auth login

Verify

验证

gh auth status
undefined
gh auth status
undefined

Common Commands

常用命令

Pull Requests

拉取请求(PR)

bash
undefined
bash
undefined

List 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
undefined
gh pr merge 55 --squash --repo owner/repo
undefined

Issues

议题(Issues)

bash
undefined
bash
undefined

List 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
undefined
gh issue close 42 --repo owner/repo
undefined

CI/Workflow Runs

CI/工作流运行

bash
undefined
bash
undefined

List 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
undefined
gh run rerun <run-id> --failed --repo owner/repo
undefined

API Queries

API查询

bash
undefined
bash
undefined

Get 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}'
undefined
gh api repos/owner/repo --jq '{stars: .stargazers_count, forks: .forks_count}'
undefined

JSON Output

JSON输出格式

Most commands support
--json
for structured output with
--jq
filtering:
bash
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
参数以生成结构化输出,并可通过
--jq
进行过滤:
bash
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
undefined
bash
undefined

Get 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
undefined
PR=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
undefined

Issue Triage

议题分类处理

bash
undefined
bash
undefined

Quick issue triage view

快速查看待分类议题

gh issue list --repo owner/repo --state open --json number,title,labels,createdAt
--jq '.[] | "[(.number)] (.title) - ([.labels[].name] | join(", ")) ((.createdAt[:10]))"'
undefined
gh issue list --repo owner/repo --state open --json number,title,labels,createdAt
--jq '.[] | "[(.number)] (.title) - ([.labels[].name] | join(", ")) ((.createdAt[:10]))"'
undefined

Notes

注意事项

  • Always specify
    --repo owner/repo
    when not in a git directory
  • Use URLs directly:
    gh pr view https://github.com/owner/repo/pull/55
  • Rate limits apply; use
    gh api --cache 1h
    for repeated queries
  • 当不在Git目录下时,务必指定
    --repo owner/repo
    参数
  • 可直接使用URL:
    gh pr view https://github.com/owner/repo/pull/55
  • 存在调用频率限制;对于重复查询,使用
    gh api --cache 1h
    进行缓存