github

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub Skill

GitHub Skill

This skill provides guidance for working with GitHub using the official
gh
CLI tool. All GitHub operations (issues, PRs, workflows, repositories) are performed using
gh
commands.
本Skill提供了使用官方
gh
CLI工具操作GitHub的指导。所有GitHub操作(议题、PR、工作流、仓库)均通过
gh
命令执行。

Prerequisites

前提条件

Quick install:
bash
undefined
快速安装:
bash
undefined

macOS

macOS

brew install gh
brew install gh

Linux (Debian/Ubuntu)

Linux (Debian/Ubuntu)

sudo apt install gh
sudo apt install gh

Fedora/RHEL/CentOS

Fedora/RHEL/CentOS

sudo dnf install gh
sudo dnf install gh

Windows

Windows

winget install --id GitHub.cli
undefined
winget install --id GitHub.cli
undefined

Authentication

身份验证

bash
undefined
bash
undefined

Authenticate with GitHub

登录GitHub进行身份验证

gh auth login
gh auth login

Verify authentication

验证身份状态

gh auth status

See [GitHub CLI Authentication](https://cli.github.com/manual/gh_auth_login) for details.
gh auth status

详情请查看 [GitHub CLI 身份验证](https://cli.github.com/manual/gh_auth_login)。

Commands

命令

Issues

议题管理

bash
gh issue list                    # List issues
gh issue view 123                # View issue details
gh issue create                  # Create new issue
gh issue comment 123             # Add comment
gh issue close 123               # Close issue
gh issue edit 123 --add-label bug  # Edit issue
Full reference: gh issue
bash
gh issue list                    # 列出所有议题
gh issue view 123                # 查看指定议题详情
gh issue create                  # 创建新议题
gh issue comment 123             # 为议题添加评论
gh issue close 123               # 关闭议题
gh issue edit 123 --add-label bug  # 编辑议题(添加bug标签)
完整参考:gh issue

Pull Requests

拉取请求(PR)

bash
gh pr list                       # List PRs
gh pr view 456                   # View PR details
gh pr create                     # Create new PR
gh pr review 456 --approve       # Approve PR
gh pr merge 456 --squash         # Merge PR
gh pr checkout 456               # Checkout PR branch
gh pr diff 456                   # View PR diff
gh pr checks 456                 # View CI status
Full reference: gh pr
bash
gh pr list                       # 列出所有PR
gh pr view 456                   # 查看指定PR详情
gh pr create                     # 创建新PR
gh pr review 456 --approve       # 批准PR
gh pr merge 456 --squash         # 合并PR(采用压缩合并方式)
gh pr checkout 456               # 切换到PR对应的分支
gh pr diff 456                   # 查看PR的代码差异
gh pr checks 456                 # 查看CI状态
完整参考:gh pr

Workflows & Actions

工作流与Actions

bash
gh workflow list                 # List workflows
gh workflow run "CI"             # Trigger workflow
gh run list                      # List workflow runs
gh run view 123456               # View run details
gh run watch 123456              # Watch run progress
gh run download 123456           # Download artifacts
gh run rerun 123456 --failed     # Rerun failed jobs
Full references:
bash
gh workflow list                 # 列出所有工作流
gh workflow run "CI"             # 触发指定工作流
gh run list                      # 列出所有工作流运行记录
gh run view 123456               # 查看指定工作流运行详情
gh run watch 123456              # 实时监控工作流运行进度
gh run download 123456           # 下载工作流产物
gh run rerun 123456 --failed     # 重新运行失败的任务
完整参考:

Repositories

仓库管理

bash
gh repo list                     # List repositories
gh repo view OWNER/REPO          # View repository
gh repo create                   # Create repository
gh repo clone OWNER/REPO         # Clone repository
gh repo fork OWNER/REPO          # Fork repository
Full reference: gh repo
bash
gh repo list                     # 列出所有仓库
gh repo view OWNER/REPO          # 查看指定仓库信息
gh repo create                   # 创建新仓库
gh repo clone OWNER/REPO         # 克隆仓库
gh repo fork OWNER/REPO          # Fork仓库
完整参考:gh repo

Search

搜索功能

bash
gh search repos "machine learning"   # Search repositories
gh search issues "is:open label:bug" # Search issues
gh search prs "is:open"              # Search pull requests
gh search code "function auth"       # Search code
Full reference: gh search
bash
gh search repos "machine learning"   # 搜索仓库
gh search issues "is:open label:bug" # 搜索议题
gh search prs "is:open"              # 搜索拉取请求
gh search code "function auth"       # 搜索代码
完整参考:gh search

Examples

使用示例

Daily PR Review

日常PR评审

bash
undefined
bash
undefined

List PRs waiting for your review

列出需要你评审的PR

gh pr list --search "review-requested:@me"
gh pr list --search "review-requested:@me"

Review a specific PR

评审指定PR

gh pr view 456 gh pr checks 456 gh pr diff 456 gh pr review 456 --approve
undefined
gh pr view 456 gh pr checks 456 gh pr diff 456 gh pr review 456 --approve
undefined

Create Issue and Link PR

创建议题并关联PR

bash
undefined
bash
undefined

Create issue

创建议题

gh issue create --title "Bug: Login fails" --body "Description" --label bug
gh issue create --title "Bug: Login fails" --body "Description" --label bug

Create PR that fixes it (use issue number in title/body)

创建修复该议题的PR(在标题/正文中使用议题编号)

gh pr create --title "Fix login bug (#123)" --body "Fixes #123"
undefined
gh pr create --title "Fix login bug (#123)" --body "Fixes #123"
undefined

Monitor CI Pipeline

监控CI流水线

bash
undefined
bash
undefined

Watch latest workflow run

监控最新的工作流运行

gh run watch $(gh run list --limit 1 --json databaseId --jq '.[0].databaseId')
gh run watch $(gh run list --limit 1 --json databaseId --jq '.[0].databaseId')

Check failed runs

查看失败的运行记录

gh run list --status failure
gh run list --status failure

Rerun failed jobs

重新运行失败的任务

gh run rerun RUNID --failed

See [common-workflows.md](references/common-workflows.md) for more examples.
gh run rerun RUNID --failed

更多示例请查看 [common-workflows.md](references/common-workflows.md)。

Advanced Usage

高级用法

JSON Output for Scripting

生成JSON输出用于脚本开发

bash
undefined
bash
undefined

Get specific fields

获取指定字段

gh issue list --json number,title,author
gh issue list --json number,title,author

Process with jq

使用jq处理输出

gh pr list --json number,title | jq '.[] | "(.number): (.title)"'
gh pr list --json number,title | jq '.[] | "(.number): (.title)"'

Export to CSV

导出为CSV格式

gh issue list --json number,title,author | jq -r '.[] | @csv'
undefined
gh issue list --json number,title,author | jq -r '.[] | @csv'
undefined

GitHub API Access

访问GitHub API

For operations not covered by gh commands:
bash
undefined
对于gh命令未覆盖的操作:
bash
undefined

Make authenticated API request

发起已验证的API请求

gh api repos/OWNER/REPO/issues
gh api repos/OWNER/REPO/issues

POST request

发起POST请求

gh api repos/OWNER/REPO/issues -X POST -f title="Issue" -f body="Text"
gh api repos/OWNER/REPO/issues -X POST -f title="Issue" -f body="Text"

Process response

处理响应结果

gh api repos/OWNER/REPO | jq '.stargazers_count'

Full reference: [gh api](https://cli.github.com/manual/gh_api)
gh api repos/OWNER/REPO | jq '.stargazers_count'

完整参考:[gh api](https://cli.github.com/manual/gh_api)

Aliases for Frequent Operations

为高频操作设置别名

bash
undefined
bash
undefined

Create shortcuts

创建快捷别名

gh alias set prs 'pr list --author @me' gh alias set issues 'issue list --assignee @me' gh alias set review 'pr list --search "review-requested:@me"'
gh alias set prs 'pr list --author @me' gh alias set issues 'issue list --assignee @me' gh alias set review 'pr list --search "review-requested:@me"'

Use them

使用别名

gh prs gh issues gh review
undefined
gh prs gh issues gh review
undefined

Rate Limits

速率限制

GitHub enforces rate limits for API requests:
  • Core API: 5,000 requests/hour
  • Search API: 30 requests/minute
Check current status:
bash
gh api rate_limit --jq '.rate'
Best practices for bulk operations:
  • Check rate limit before starting
  • Use specific filters to reduce result sets
  • Prefer
    --limit
    flag to control results
  • Use exact issue/PR numbers when known
GitHub对API请求实施速率限制:
  • 核心API:每小时5000次请求
  • 搜索API:每分钟30次请求
查看当前速率限制状态:
bash
gh api rate_limit --jq '.rate'
批量操作最佳实践:
  • 开始前检查速率限制
  • 使用特定过滤器减少结果集
  • 优先使用
    --limit
    标志控制结果数量
  • 已知议题/PR编号时直接使用编号

Configuration

配置

bash
undefined
bash
undefined

View configuration

查看当前配置

gh config list
gh config list

Set default editor

设置默认编辑器

gh config set editor vim
gh config set editor vim

Set git protocol

设置Git协议

gh config set git_protocol ssh

Configuration stored in `~/.config/gh/config.yml`
gh config set git_protocol ssh

配置文件存储在 `~/.config/gh/config.yml`

Troubleshooting

故障排查

bash
undefined
bash
undefined

Check authentication

检查身份验证状态

gh auth status
gh auth status

Re-authenticate

重新进行身份验证

gh auth login
gh auth login

Enable debug logging

启用调试日志

GH_DEBUG=1 gh issue list
GH_DEBUG=1 gh issue list

Check gh version

查看gh版本

gh --version
undefined
gh --version
undefined

Official Documentation

官方文档

Summary

总结

The GitHub skill uses the official
gh
CLI exclusively. No custom scripts are needed -
gh
provides comprehensive functionality for all GitHub operations.
Quick start:
  1. Install:
    brew install gh
    (or equivalent for your OS)
  2. Authenticate:
    gh auth login
  3. Verify:
    gh auth status
  4. Use:
    gh issue list
    ,
    gh pr create
    , etc.
For detailed command reference, use
gh <command> --help
or visit https://cli.github.com/manual/.
本GitHub Skill完全使用官方
gh
CLI工具,无需自定义脚本——
gh
为所有GitHub操作提供了全面的功能支持。
快速开始:
  1. 安装:
    brew install gh
    (其他系统使用对应安装命令)
  2. 身份验证:
    gh auth login
  3. 验证:
    gh auth status
  4. 使用:
    gh issue list
    gh pr create
    等命令
如需详细命令参考,使用
gh <command> --help
或访问 https://cli.github.com/manual/