github-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitHub CLI Skill
GitHub CLI Skill
Provides patterns for the CLI to interact with GitHub repositories, services, and APIs directly from the terminal. Covers authentication, repository management, issues, pull requests, actions, releases, projects, search, and the REST/GraphQL API. Git workflow patterns (branching, commits, CI/CD) are handled by a separate skill.
gh提供 CLI的使用范式,可直接在终端中与GitHub仓库、服务及API进行交互。涵盖认证、仓库管理、议题、拉取请求、Actions、版本发布、项目、搜索以及REST/GraphQL API。Git工作流范式(分支、提交、CI/CD)由单独的技能文档处理。
ghQuick Reference
快速参考
| Area | Key Commands |
|---|---|
| Auth | |
| Repos | |
| Browse | |
| Issues | |
| Pull Requests | |
| Actions | |
| Releases | |
| Projects | |
| Search | |
| API | |
| Security | |
| Status | |
| Codespaces | |
| 领域 | 核心命令 |
|---|---|
| 认证 | |
| 仓库 | |
| 浏览 | |
| 议题 | |
| 拉取请求 | |
| Actions | |
| 版本发布 | |
| 项目 | |
| 搜索 | |
| API | |
| 安全 | |
| 状态 | |
| Codespaces | |
Common Workflows
常见工作流
| Workflow | Commands |
|---|---|
| Quick PR | |
| Draft PR | |
| Review and merge | |
| Auto-merge PR | |
| Check CI | |
| Rerun failed CI | |
| Create release | |
| Search code | |
| Add issue to project | |
| Verify artifact | |
| Trigger workflow | |
| Revert merged PR | |
| Sync fork | |
| 工作流名称 | 命令 |
|---|---|
| 快速创建PR | |
| 草稿PR | |
| 评审与合并 | |
| 自动合并PR | |
| 检查CI状态 | |
| 重新运行失败的CI | |
| 创建版本发布 | |
| 搜索代码 | |
| 将议题添加到项目 | |
| 验证工件 | |
| 触发工作流 | |
| 回滚已合并的PR | |
| 同步复刻仓库 | |
Output Formatting
输出格式化
Most list and view commands support structured output for scripting and automation.
gh| Flag | Purpose |
|---|---|
| Output specified fields as JSON |
| Filter JSON with jq expressions |
| Format JSON with Go templates |
| Open the resource in a browser |
| Include comments (issues and PRs) |
大多数列表和查看命令支持结构化输出,适用于脚本编写和自动化场景。
gh| 参数 | 用途 |
|---|---|
| 以JSON格式输出指定字段 |
| 使用jq表达式过滤JSON |
| 使用Go模板格式化JSON |
| 在浏览器中打开资源 |
| 包含评论(议题和PR) |
Scoping: Repo, Env, Org
作用域:仓库、环境、组织
Secrets and variables can be scoped to different levels.
| Scope | Flag Example |
|---|---|
| Repository | |
| Environment | |
| Organization | |
Project commands always require or .
--owner @me--owner org-name密钥和变量可作用于不同层级。
| 作用域 | 参数示例 |
|---|---|
| 仓库 | |
| 环境 | |
| 组织 | |
项目命令始终需要指定或。
--owner @me--owner org-nameAuthentication Prerequisites
认证前提条件
The CLI requires authentication before most commands work. Run to verify the current session. Missing scopes cause silent failures -- use to add scopes without re-authenticating. For CI environments, set the or environment variable instead of interactive login.
ghgh auth statusgh auth refresh -s scopeGITHUB_TOKENGH_TOKENghgh auth statusgh auth refresh -s scopeGITHUB_TOKENGH_TOKENCommon Mistakes
常见错误
| Mistake | Correct Pattern |
|---|---|
Running | Push with |
Using | Run |
Forgetting | Use |
| Using REST API when GraphQL is more efficient for nested data | Use |
| Not authenticating with correct scopes | Run |
Using | Always pass |
| Manually downloading CI artifacts | Use |
Not using | Add |
Merging without | Use |
Running | Use |
| 错误操作 | 正确操作方式 |
|---|---|
未推送分支就运行 | 创建PR前先执行 |
未检查CI状态就执行 | 先执行 |
从规范提交创建PR时忘记使用 | 使用 |
| 处理嵌套数据时使用REST API而不是更高效的GraphQL | 对于需要在单次调用中获取关联对象的查询,使用 |
| 未使用正确权限范围进行认证 | 执行 |
执行 | 项目命令始终需要传递 |
| 手动下载CI工件 | 使用 |
编写脚本时未使用 | 添加 |
合并时未使用 | 使用 |
执行 | 字符串字段使用 |
Delegation
任务委托
- Search across repositories for code patterns or issues: Use agent with
Exploreandgh search codegh search issues - Automate multi-step release workflows: Use agent to coordinate branch creation, PR merge, and release publishing
Task - Plan repository structure and access controls: Use agent to design team permissions, branch protection, and workflow architecture
Plan
- 跨仓库搜索代码模式或议题:使用agent配合
Explore和gh search codegh search issues - 自动化多步骤发布工作流:使用agent协调分支创建、PR合并和版本发布
Task - 规划仓库结构和访问控制:使用agent设计团队权限、分支保护和工作流架构
Plan
References
参考资料
- Repos & Auth -- Authentication, repository management, configuration, extensions, aliases
- Issues -- Issue CRUD, labels, assignments, pinning, transferring, development branches
- Pull Requests -- PR creation, review, merge, checkout, checks, diff, auto-merge
- Actions -- Workflow runs, manual triggers, secrets, variables, caches, artifact downloads
- Releases & Search -- Releases, attestation verification, search, gists, SSH/GPG keys
- Projects & API -- Projects v2 management, REST API, GraphQL API, rulesets, status
- 仓库与认证 -- 认证、仓库管理、配置、扩展、别名
- 议题 -- 议题的增删改查、标签、分配、置顶、转移、开发分支
- 拉取请求 -- PR创建、评审、合并、检出、检查、差异对比、自动合并
- Actions -- 工作流运行、手动触发、密钥、变量、缓存、工件下载
- 版本发布与搜索 -- 版本发布、证明验证、搜索、Gist、SSH/GPG密钥
- 项目与API -- Projects v2管理、REST API、GraphQL API、规则集、状态