github
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitHub Skill
GitHub Skill
This skill provides guidance for working with GitHub using the official CLI tool. All GitHub operations (issues, PRs, workflows, repositories) are performed using commands.
ghgh本Skill提供了使用官方 CLI工具操作GitHub的指导。所有GitHub操作(议题、PR、工作流、仓库)均通过命令执行。
ghghPrerequisites
前提条件
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
undefinedwinget install --id GitHub.cli
undefinedAuthentication
身份验证
bash
undefinedbash
undefinedAuthenticate 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 issueFull 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 statusFull 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 jobsFull 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 repositoryFull 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 codeFull 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
undefinedbash
undefinedList 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
undefinedgh pr view 456
gh pr checks 456
gh pr diff 456
gh pr review 456 --approve
undefinedCreate Issue and Link PR
创建议题并关联PR
bash
undefinedbash
undefinedCreate 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"
undefinedgh pr create --title "Fix login bug (#123)" --body "Fixes #123"
undefinedMonitor CI Pipeline
监控CI流水线
bash
undefinedbash
undefinedWatch 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
undefinedbash
undefinedGet 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'
undefinedgh issue list --json number,title,author | jq -r '.[] | @csv'
undefinedGitHub API Access
访问GitHub API
For operations not covered by gh commands:
bash
undefined对于gh命令未覆盖的操作:
bash
undefinedMake 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
undefinedbash
undefinedCreate 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
undefinedgh prs
gh issues
gh review
undefinedRate 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 flag to control results
--limit - Use exact issue/PR numbers when known
GitHub对API请求实施速率限制:
- 核心API:每小时5000次请求
- 搜索API:每分钟30次请求
查看当前速率限制状态:
bash
gh api rate_limit --jq '.rate'批量操作最佳实践:
- 开始前检查速率限制
- 使用特定过滤器减少结果集
- 优先使用标志控制结果数量
--limit - 已知议题/PR编号时直接使用编号
Configuration
配置
bash
undefinedbash
undefinedView 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
undefinedbash
undefinedCheck 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
undefinedgh --version
undefinedOfficial Documentation
官方文档
- GitHub CLI Manual: https://cli.github.com/manual/
- GitHub CLI Repository: https://github.com/cli/cli
- GitHub API Documentation: https://docs.github.com/en/rest
- GitHub Actions: https://docs.github.com/en/actions
- GitHub CLI 手册:https://cli.github.com/manual/
- GitHub CLI 仓库:https://github.com/cli/cli
- GitHub API 文档:https://docs.github.com/en/rest
- GitHub Actions:https://docs.github.com/en/actions
Summary
总结
The GitHub skill uses the official CLI exclusively. No custom scripts are needed - provides comprehensive functionality for all GitHub operations.
ghghQuick start:
- Install: (or equivalent for your OS)
brew install gh - Authenticate:
gh auth login - Verify:
gh auth status - Use: ,
gh issue list, etc.gh pr create
For detailed command reference, use or visit https://cli.github.com/manual/.
gh <command> --help本GitHub Skill完全使用官方 CLI工具,无需自定义脚本——为所有GitHub操作提供了全面的功能支持。
ghgh快速开始:
- 安装:(其他系统使用对应安装命令)
brew install gh - 身份验证:
gh auth login - 验证:
gh auth status - 使用:、
gh issue list等命令gh pr create
如需详细命令参考,使用或访问 https://cli.github.com/manual/。
gh <command> --help