github-operations
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitHub Operations
GitHub操作
Comprehensive GitHub CLI () operations for project management, from basic issue creation to advanced Projects v2 integration and milestone tracking via REST API.
gh全面的GitHub CLI()项目管理操作指南,从基础议题创建到通过REST API实现的Projects v2高级集成与里程碑跟踪。
ghOverview
概述
- Creating and managing GitHub issues and PRs
- Working with GitHub Projects v2 custom fields
- Managing milestones (sprints, releases) via REST API
- Automating bulk operations with
gh - Running GraphQL queries for complex operations
- 创建和管理GitHub议题与拉取请求(PRs)
- 操作GitHub Projects v2自定义字段
- 通过REST API管理里程碑(迭代、发布)
- 使用实现批量操作自动化
gh - 运行GraphQL查询以完成复杂操作
Quick Reference
快速参考
Issue Operations
议题操作
bash
undefinedbash
undefinedCreate issue with labels and milestone
创建带标签和里程碑的议题
gh issue create --title "Bug: API returns 500" --body "..." --label "bug" --milestone "Sprint 5"
gh issue create --title "Bug: API returns 500" --body "..." --label "bug" --milestone "Sprint 5"
List and filter issues
列出并筛选议题
gh issue list --state open --label "backend" --assignee @me
gh issue list --state open --label "backend" --assignee @me
Edit issue metadata
编辑议题元数据
gh issue edit 123 --add-label "high" --milestone "v2.0"
undefinedgh issue edit 123 --add-label "high" --milestone "v2.0"
undefinedPR Operations
PR操作
bash
undefinedbash
undefinedCreate PR with reviewers
创建带指定评审人的PR
gh pr create --title "feat: Add search" --body "..." --base dev --reviewer @teammate
gh pr create --title "feat: Add search" --body "..." --base dev --reviewer @teammate
Watch CI status and auto-merge
监控CI状态并自动合并
gh pr checks 456 --watch
gh pr merge 456 --auto --squash --delete-branch
gh pr checks 456 --watch
gh pr merge 456 --auto --squash --delete-branch
Resume a session linked to a PR (CC 2.1.27)
恢复与PR关联的会话(CC 2.1.27版本)
claude --from-pr 456 # Resume session with PR context (diff, comments, review status)
claude --from-pr https://github.com/org/repo/pull/456
> **Tip (CC 2.1.27):** Sessions created via `gh pr create` are automatically linked to the PR. Use `--from-pr` to resume with full PR context.claude --from-pr 456 # 恢复包含PR上下文(差异、评论、评审状态)的会话
claude --from-pr https://github.com/org/repo/pull/456
> **提示(CC 2.1.27版本)**:通过`gh pr create`创建的会话会自动与PR关联。使用`--from-pr`可恢复包含完整PR上下文的会话。Milestone Operations (REST API)
里程碑操作(REST API)
bash
undefinedbash
undefinedList milestones with progress
列出带进度的里程碑
gh api repos/:owner/:repo/milestones --jq '.[] | "(.title): (.closed_issues)/(.open_issues + .closed_issues)"'
gh api repos/:owner/:repo/milestones --jq '.[] | "(.title): (.closed_issues)/(.open_issues + .closed_issues)"'
Create milestone with due date
创建带截止日期的里程碑
gh api -X POST repos/:owner/:repo/milestones
-f title="Sprint 8" -f due_on="2026-02-15T00:00:00Z"
-f title="Sprint 8" -f due_on="2026-02-15T00:00:00Z"
gh api -X POST repos/:owner/:repo/milestones
-f title="Sprint 8" -f due_on="2026-02-15T00:00:00Z"
-f title="Sprint 8" -f due_on="2026-02-15T00:00:00Z"
Close milestone
关闭里程碑
gh api -X PATCH repos/:owner/:repo/milestones/5 -f state=closed
undefinedgh api -X PATCH repos/:owner/:repo/milestones/5 -f state=closed
undefinedProjects v2 Operations
Projects v2操作
bash
undefinedbash
undefinedAdd issue to project
向项目中添加议题
gh project item-add 1 --owner @me --url https://github.com/org/repo/issues/123
gh project item-add 1 --owner @me --url https://github.com/org/repo/issues/123
Set custom field (requires GraphQL)
设置自定义字段(需要GraphQL)
gh api graphql -f query='mutation {...}' -f projectId="..." -f itemId="..."
---gh api graphql -f query='mutation {...}' -f projectId="..." -f itemId="..."
---JSON Output Patterns
JSON输出模式
bash
undefinedbash
undefinedGet issue numbers matching criteria
获取符合条件的议题编号
gh issue list --json number,labels --jq '[.[] | select(.labels[].name == "bug")] | .[].number'
gh issue list --json number,labels --jq '[.[] | select(.labels[].name == "bug")] | .[].number'
PR summary with author
包含作者信息的PR摘要
gh pr list --json number,title,author --jq '.[] | "(.number): (.title) by (.author.login)"'
gh pr list --json number,title,author --jq '.[] | "(.number): (.title) by (.author.login)"'
Find ready-to-merge PRs
查找可合并的PR
gh pr list --json number,reviewDecision,statusCheckRollupState
--jq '[.[] | select(.reviewDecision == "APPROVED" and .statusCheckRollupState == "SUCCESS")]'
--jq '[.[] | select(.reviewDecision == "APPROVED" and .statusCheckRollupState == "SUCCESS")]'
---gh pr list --json number,reviewDecision,statusCheckRollupState
--jq '[.[] | select(.reviewDecision == "APPROVED" and .statusCheckRollupState == "SUCCESS")]'
--jq '[.[] | select(.reviewDecision == "APPROVED" and .statusCheckRollupState == "SUCCESS")]'
---Key Concepts
核心概念
Milestone vs Epic
里程碑 vs 史诗(Epic)
| Milestones | Epics |
|---|---|
| Time-based (sprints, releases) | Topic-based (features) |
| Has due date | No due date |
| Progress bar | Task list checkbox |
| Native REST API | Needs workarounds |
Rule: Use milestones for "when", use parent issues for "what".
| 里程碑 | 史诗(Epic) |
|---|---|
| 基于时间(迭代、发布) | 基于主题(功能) |
| 有截止日期 | 无截止日期 |
| 进度条 | 任务列表复选框 |
| 原生REST API支持 | 需要变通方案 |
规则:用里程碑管理「时间节点」,用父议题管理「内容范围」。
Projects v2 Custom Fields
Projects v2自定义字段
Projects v2 uses GraphQL for setting custom fields (Status, Priority, Domain). Basic commands work for listing and adding items, but field updates require GraphQL mutations.
gh projectProjects v2使用GraphQL来设置自定义字段(状态、优先级、领域)。基础的命令可用于列出和添加项目项,但字段更新需要GraphQL变更操作。
gh projectBest Practices
最佳实践
- Always use for scripting - Parse with
--jsonfor reliability--jq - Non-interactive mode for automation - Use ,
--titleflags--body - Check rate limits before bulk operations -
gh api rate_limit - Use heredocs for multi-line content -
--body "$(cat <<'EOF'...EOF)" - Link issues in PRs - ,
Closes #123Fixes #456 - Use ISO 8601 dates - for milestone due_on
YYYY-MM-DDTHH:MM:SSZ - Close milestones, don't delete - Preserve history
- 脚本编写始终使用- 配合
--json解析以确保可靠性--jq - 自动化使用非交互模式 - 使用、
--title等参数--body - 批量操作前检查速率限制 - 执行查看
gh api rate_limit - 使用 heredoc 处理多行内容 -
--body "$(cat <<'EOF'...EOF)" - 在PR中关联议题 - 使用、
Closes #123格式Fixes #456 - 使用ISO 8601日期格式 - 里程碑截止日期使用格式
YYYY-MM-DDTHH:MM:SSZ - 关闭而非删除里程碑 - 保留历史记录
Related Skills
相关技能
- - Create pull requests with proper formatting and review assignments
create-pr - - Comprehensive PR review with specialized agents
review-pr - - GitHub release workflow with semantic versioning and changelogs
release-management - - Manage dependent PRs with rebase coordination
stacked-prs - - Automatic issue progress updates from commits
issue-progress-tracking
- - 创建格式规范且指定评审人的拉取请求
create-pr - - 借助专用Agent进行全面PR评审
review-pr - - 遵循语义化版本和变更日志的GitHub发布流程
release-management - - 管理依赖PR并协调变基操作
stacked-prs - - 通过提交记录自动更新议题进度
issue-progress-tracking
Key Decisions
关键决策
| Decision | Choice | Rationale |
|---|---|---|
| CLI vs API | gh CLI preferred | Simpler auth, better UX, handles pagination automatically |
| Output format | --json with --jq | Reliable parsing for automation, no regex parsing needed |
| Milestones vs Epics | Milestones for time | Milestones have due dates and progress bars, epics for topic grouping |
| Projects v2 fields | GraphQL mutations | gh project commands limited, GraphQL required for custom fields |
| Milestone lifecycle | Close, don't delete | Preserves history and progress tracking |
| 决策 | 选择 | 理由 |
|---|---|---|
| CLI vs API | 优先使用gh CLI | 认证更简单、用户体验更好、自动处理分页 |
| 输出格式 | 配合 | 自动化解析更可靠,无需正则表达式 |
| 里程碑 vs 史诗 | 里程碑用于时间管理 | 里程碑支持截止日期和进度条,史诗用于主题分组 |
| Projects v2字段设置 | 使用GraphQL变更 | gh project命令功能有限,自定义字段需GraphQL支持 |
| 里程碑生命周期 | 关闭而非删除 | 保留历史记录和进度跟踪信息 |
References
参考资料
- Issue Management - Bulk operations, templates, sub-issues
- PR Workflows - Reviews, merge strategies, auto-merge
- Milestone API - REST API patterns for milestone CRUD
- Projects v2 - Custom fields, GraphQL mutations
- GraphQL API - Complex queries, pagination, bulk operations
- 议题管理 - 批量操作、模板、子议题
- PR工作流 - 评审、合并策略、自动合并
- 里程碑API - 里程碑增删改查的REST API模式
- Projects v2 - 自定义字段、GraphQL变更
- GraphQL API - 复杂查询、分页、批量操作
Examples
示例
- Automation Scripts - Ready-to-use scripts for bulk operations, PR automation, milestone management
- 自动化脚本 - 可直接使用的批量操作、PR自动化、里程碑管理脚本