gh-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitHub CLI Quick Reference
GitHub CLI 快速参考
The CLI is GitHub's official command-line tool. This is a quick reference for
common workflows—for comprehensive docs, see https://cli.github.com/manual
ghghGetting Help
获取帮助
bash
gh --help # List all commands
gh <command> --help # Help for specific command
gh auth status # Check authenticationbash
gh --help # 列出所有命令
gh <command> --help # 查看特定命令的帮助
gh auth status # 检查认证状态Discovery Patterns
发现模式
bash
gh <command> --web # Open in browser
gh <command> --json FIELDS # JSON output for scripting
gh <command> <subcommand> -h # Quick help for any command
gh <command> list --limit N # Limit results to avoid large output (default: 20-30)Use tab completion to explore available commands and flags.
Important: Always use when querying lists to avoid overwhelming output,
especially with , , , etc.
--limitpr listissue listrun listbash
gh <command> --web # 在浏览器中打开
gh <command> --json FIELDS # 输出JSON格式用于脚本编写
gh <command> <subcommand> -h # 查看任意命令的快速帮助
gh <command> list --limit N # 限制结果数量以避免输出过多(默认:20-30条)使用标签补全功能探索可用的命令和参数。
重要提示: 查询列表时请始终使用参数,避免输出内容过多,尤其是使用、、等命令时。
--limitpr listissue listrun listCommon Workflows
常见工作流
PR Workflow
PR工作流
bash
undefinedbash
undefinedCreate PR
创建PR
gh pr create --fill # Use commit messages for title/body
gh pr create --web # Open browser to create PR
gh pr create --fill # 使用提交信息作为标题/正文
gh pr create --web # 打开浏览器创建PR
View and checkout
查看并检出PR
gh pr list # List PRs
gh pr view [NUMBER] # View PR details
gh pr checkout NUMBER # Checkout PR locally
gh pr list # 列出PR
gh pr view [NUMBER] # 查看PR详情
gh pr checkout NUMBER # 在本地检出PR
Review
评审PR
gh pr review NUMBER --approve
gh pr review NUMBER --comment -b "feedback"
gh pr review NUMBER --approve
gh pr review NUMBER --comment -b "反馈内容"
Merge
合并PR
gh pr merge --squash --delete-branch
undefinedgh pr merge --squash --delete-branch
undefinedReview Workflow
评审工作流
bash
undefinedbash
undefinedFind PRs needing your review
查找需要你评审的PR
gh pr list --search "review-requested:@me"
gh pr list --search "review-requested:@me"
Review process
评审流程
gh pr checkout NUMBER
gh pr checkout NUMBER
... test locally ...
... 本地测试 ...
gh pr review NUMBER --approve
undefinedgh pr review NUMBER --approve
undefinedCI/CD Debugging
CI/CD 调试
bash
undefinedbash
undefinedCheck recent runs
查看最近的运行记录
gh run list --limit 5
gh run list --status failure
gh run list --limit 5
gh run list --status failure
View logs
查看日志
gh run view RUN_ID --log-failed
gh run view RUN_ID --log-failed
Rerun after fix
修复后重新运行
gh run rerun RUN_ID --failed
undefinedgh run rerun RUN_ID --failed
undefinedIssue Triage
Issue 分类处理
bash
gh issue list
gh issue list --assignee @me
gh issue create --title "Title" --body "Description"
gh issue view NUMBER
gh issue comment NUMBER -b "Comment"
gh issue close NUMBERbash
gh issue list
gh issue list --assignee @me
gh issue create --title "标题" --body "描述内容"
gh issue view NUMBER
gh issue comment NUMBER -b "评论内容"
gh issue close NUMBERCore Commands Quick Reference
核心命令快速参考
Pull Requests
拉取请求(PR)
bash
gh pr list [--state open|closed|merged] [--author @me]
gh pr create [--draft] [--title "..."] [--body "..."]
gh pr view [NUMBER] [--web]
gh pr checkout NUMBER
gh pr diff [NUMBER]
gh pr merge [NUMBER] [--squash|--merge|--rebase]bash
gh pr list [--state open|closed|merged] [--author @me]
gh pr create [--draft] [--title "..."] [--body "..."]
gh pr view [NUMBER] [--web]
gh pr checkout NUMBER
gh pr diff [NUMBER]
gh pr merge [NUMBER] [--squash|--merge|--rebase]Issues
Issue
bash
gh issue list [--assignee @me] [--label "bug"]
gh issue create [--title "..."] [--body "..."]
gh issue view NUMBER [--web]
gh issue close NUMBERbash
gh issue list [--assignee @me] [--label "bug"]
gh issue create [--title "..."] [--body "..."]
gh issue view NUMBER [--web]
gh issue close NUMBERWorkflows & Runs
工作流与运行记录
bash
gh run list [--workflow "CI"] [--status failure]
gh run view RUN_ID [--log] [--log-failed]
gh run watch RUN_ID
gh workflow run WORKFLOW_FILE [--ref branch]bash
gh run list [--workflow "CI"] [--status failure]
gh run view RUN_ID [--log] [--log-failed]
gh run watch RUN_ID
gh workflow run WORKFLOW_FILE [--ref branch]Repositories
仓库
bash
gh repo clone OWNER/REPO
gh repo view [--web]
gh repo fork OWNER/REPO
gh repo create NAME [--public|--private]bash
gh repo clone OWNER/REPO
gh repo view [--web]
gh repo fork OWNER/REPO
gh repo create NAME [--public|--private]Power User Tips
高级用户技巧
JSON Output
JSON 输出
bash
undefinedbash
undefinedGet structured data
获取结构化数据
gh pr list --json number,title,author
gh pr list --json number,title,author
Filter with jq
使用 jq 过滤
gh pr list --json number,title | jq '.[] | select(.number > 100)'
undefinedgh pr list --json number,title | jq '.[] | select(.number > 100)'
undefinedAPI Access
API 访问
bash
undefinedbash
undefinedDirect API calls
直接调用API
gh api repos/OWNER/REPO
gh api repos/OWNER/REPO/pulls -f title="PR Title" -f head=branch -f base=main
gh api repos/OWNER/REPO
gh api repos/OWNER/REPO/pulls -f title="PR标题" -f head=branch -f base=main
GraphQL
GraphQL 查询
gh api graphql -f query='{ viewer { login } }'
undefinedgh api graphql -f query='{ viewer { login } }'
undefinedAliases
别名
bash
gh alias set pv 'pr view'
gh alias set co 'pr checkout'
gh alias listbash
gh alias set pv 'pr view'
gh alias set co 'pr checkout'
gh alias listEnvironment Variables
环境变量
- : Authentication token
GH_TOKEN - : Default repository (OWNER/REPO format)
GH_REPO - : Preferred editor for interactive commands
GH_EDITOR - : Pager for output (e.g.,
GH_PAGER)less
- : 认证令牌
GH_TOKEN - : 默认仓库(格式为OWNER/REPO)
GH_REPO - : 交互式命令首选的编辑器
GH_EDITOR - : 输出分页工具(例如
GH_PAGER)less
Finding Your Work
查找你的工作内容
bash
gh pr list --author @me
gh issue list --assignee @me
gh search prs "author:username is:open"
gh search issues "assignee:username is:open"bash
gh pr list --author @me
gh issue list --assignee @me
gh search prs "author:username is:open"
gh search issues "assignee:username is:open"