Communitygithub.com

GitHub CLI (gh) 技能

通过终端直接管理 GitHub 议题、拉取请求、分支、提交和代码审查的 GitHub CLI (gh) 集成。

GitHub CLI (gh) 技能 是什么?

该技能使 AI 代理能够直接从终端使用 GitHub CLI (gh) 与 GitHub 仓库进行交互,支持管理议题、拉取请求、分支、提交和代码审查,以及 GitHub Actions 工作流。核心优势在于无需切换至浏览器即可完成仓库管理任务,显著提升开发效率。支持所有安装了 gh CLI 并完成身份验证的环境。工作流程包括议题的创建、查看、更新和关闭;分支创建与提交推送;拉取请求的创建、审查、评论、合并;以及 GitHub Actions 工作流的触发、监控和日志查看。技能文档还提供了常用标志参考、环境变量配置以及使用多行描述和 Markdown 时的实用技巧,帮助用户避免常见的 shell 解释问题。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/cdcoonce/Portfolio_Website/tree/HEAD/.claude/skills/github-cli

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

GitHub CLI (gh) 技能 是做什么的?

使用 gh CLI 从终端与 GitHub 仓库、议题、拉取请求和 GitHub Actions 工作流进行交互。

前提条件

验证已安装 gh 并完成身份验证:

gh --version
gh auth status

如果尚未验证身份,请运行 gh auth login 并按照提示操作。

核心工作流程

议题管理

# 列出议题
gh issue list                             # 当前仓库中开放的议题
gh issue list --state all                 # 所有议题,包括已关闭的
gh issue list --assignee @me              # 分配给你的议题
gh issue list --label "bug"               # 按标签筛选

# 创建议题
gh issue create -t "标题" -b "描述"
gh issue create -t "标题" --label "bug,priority:high" --milestone "milestone-1"
gh issue create                           # 交互模式

# 查看/更新议题
gh issue view 123                         # 查看议题详情
gh issue view 123 --web                   # 在浏览器中打开
gh issue edit 123 --add-label "in-progress"
gh issue close 123
gh issue reopen 123

# 添加评论
gh issue comment 123 -b "正在处理”

分支与提交工作流程

# 创建功能/修复分支
git checkout -b feature/my-feature
git checkout -b fix/issue-123
git checkout -b draft/wip-experiment

# 暂存并提交更改
git add .
git commit -m "feat: 添加新功能"
git commit -m "fix: 解决 issue #123"

# 将分支推送到远程
git push -u origin feature/my-feature

拉取请求管理

# 创建 PR(多种方法)
gh pr create                              # 交互模式
gh pr create --fill                       # 从提交中自动填充
gh pr create --draft                      # 创建为草稿
gh pr create --draft --fill               # 草稿并自动填充
gh pr create -t "标题" -b "描述" -B main
gh pr create --label "review-needed" --assignee @me

# 列出 PR
gh pr list                                # 开放的 PR
gh pr list --assignee @me                 # 你的 PR
gh pr list --search "review-requested:@me"  # 请求你审查的 PR
gh pr list --draft                        # 仅草稿 PR

# 查看 PR 详情
gh pr view 45                             # 在终端中查看 PR
gh pr view 45 --web                       # 在浏览器中打开

代码审查工作流程

# 本地检出 PR 进行测试
gh pr checkout 45                         # 本地检出 PR 分支

# 审查更改
gh pr diff 45                             # 查看 PR 差异
gh pr diff                                # 当前分支 PR 的差异

# 添加审查评论
gh pr comment 45 -b "LGTM,第 42 行有小的建议"
gh pr comment -b "请添加测试"              # 在当前分支的 PR 上评论

# 提交正式审查
gh pr review 45 --approve
gh pr review 45 --request-changes -b "请修复错误处理"
gh pr review 45 --comment -b "总体不错,有一些建议"

# 合并
gh pr merge 45                            # 交互式合并
gh pr merge 45 --squash                   # 压缩合并(Squash merge)
gh pr merge 45 --rebase                   # 变基合并(Rebase merge)
gh pr merge 45 --merge                    # 标准合并提交
gh pr merge 45 --auto                     # 检查通过后自动合并

更新现有 PR

gh pr edit 45 --title "新标题"
gh pr edit 45 --body "更新后的描述"
gh pr edit 45 --base develop
gh pr edit 45 --add-label "ready-for-review"
gh pr ready 45                            # 标记为就绪(移除草稿状态)

GitHub Actions 工作流管理

# 列出工作流运行
gh run list                               # 最近的工作流运行
gh run list --workflow=ci.yml             # 特定工作流
gh run list --status=failure              # 仅失败的运行

# 查看工作流运行详情
gh run view                               # 交互式运行选择器
gh run view 12345                         # 特定运行
gh run view 12345 --web                   # 在浏览器中打开

# 触发工作流
gh workflow run ci.yml                    # 在默认分支上运行
gh workflow run ci.yml --ref feature/x    # 在特定分支上运行
gh workflow run ci.yml -f key=value       # 带输入参数

# 重新运行失败的作业
gh run rerun 12345                        # 重新运行所有作业
gh run rerun 12345 --failed               # 仅重新运行失败的作业

# 查看作业日志
gh run view 12345 --log                   # 完整日志输出
gh run view 12345 --log-failed            # 仅失败作业的日志

# 实时观察运行过程
gh run watch                              # 观察当前运行
gh run watch 12345                        # 观察特定运行

常用标志参考

标志描述
-R, --repo OWNER/REPO目标仓库的 owner/repo
-B, --basePR 的基础分支
-H, --headPR 的头部分支
-t, --title议题/PR 的标题
-b, --body议题/PR 的主体/描述
-l, --label标签(逗号分隔)
-a, --assignee分配的用户名
-m, --milestone里程碑名称
--draft创建为草稿 PR
--fill从提交消息自动填充
--web在浏览器中打开
-y, --yes跳过确认提示

环境变量

export GH_TOKEN="ghp_xxxx"               # 个人访问令牌
export GH_HOST="github.example.com"      # GitHub Enterprise 实例
export GH_REPO="owner/repo"              # 默认仓库

技巧与注意事项

带 Markdown 的多行描述

创建包含 Markdown(代码块、反引号)的长描述议题或 PR 时,避免使用可能会因 shell 解释而失败的 heredoc。相反:

# 步骤 1:将描述写入临时文件(在 bash 之外)
# 步骤 2:从临时文件创建
github issue create -t "标题" -b "$(cat temp_description.txt)"
# 步骤 3:清理
rm temp_description.txt

这可以避免以下问题:

  • 代码块中的反引号与命令替换冲突
  • 特殊字符被 shell 解释
  • heredoc 定界符冲突

从现有文件获取描述

从 Markdown 计划文件创建议题或 PR:

# 使用 body-file 标志来获取清晰的文件描述
github issue create -t "标题" --body-file docs/plans/my-plan.md
github pr create -t "标题" --body-file docs/plans/my-plan.md

详细参考

有关全面的命令选项和示例,请参阅 references/commands.md。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

cdcoonce/Portfolio_Website

Git commit workflow with enforced conventional commit style. Use when Claude needs to stage and commit changes, craft commit messages, or the user asks to commit, make a commit, or save their work. Ensures consistent commit message format, proper scoping, and atomic commits across the project.

cdcoonce/Portfolio_Website

AI-powered code quality analysis for Python, Markdown, and Mermaid diagrams. Use this skill when: (1) reviewing code for quality issues, (2) checking Python files for PEP8 violations, unused code, missing type hints, docstring problems, complexity issues, or potential runtime errors, (3) validating Markdown documentation for broken links, heading structure, or formatting issues, (4) validating Mermaid diagram syntax, (5) the user asks for a "code review" or "quality check", (6) analyzing code snippets pasted in conversation, or (7) suggesting and applying fixes for code quality issues.

cdcoonce/Portfolio_Website

Deploy the portfolio chat agent Lambda function to AWS. Use when the user asks to deploy, redeploy, push to Lambda, update the chat agent, or after updating context files or lambda_function.py. Rebuilds the knowledge base, packages dependencies, and deploys to AWS Lambda.

cdcoonce/Portfolio_Website

Generate multiple radically different interface designs for a module using parallel sub-agents. Use when user wants to design an API, explore interface options, compare module shapes, or mentions "design it twice".

cdcoonce/Portfolio_Website

Orchestrate the full GitHub-issues-driven development lifecycle. 7-phase pipeline from brainstorm through PR with state tracking and cross-conversation resume. Use when user says "dev cycle", "development workflow", "full development pipeline", or invokes /dev-cycle.

cdcoonce/Portfolio_Website

Production Python coding standards with automatic version detection (3.10-3.13). Use when writing, reviewing, or refactoring Python to ensure adherence to modern type syntax, LBYL exception handling, pathlib operations, ABC-based interfaces, and production-tested patterns. Not Dagster-specific - applies to any Python project.

cdcoonce/Portfolio_Website

Set up Claude Code hooks to block dangerous git commands (push, reset --hard, clean, branch -D, etc.) before they execute. Use when user wants to prevent destructive git operations, add git safety hooks, or block git push/reset in Claude Code.

cdcoonce/Portfolio_Website

Interview the user relentlessly about a plan or design until reaching shared understanding, resolving each branch of the decision tree. Use when user wants to stress-test a plan, get grilled on their design, or mentions "grill me".

cdcoonce/Portfolio_Website

Explore a codebase to find opportunities for architectural improvement, focusing on making the codebase more testable by deepening shallow modules. Use when user wants to improve architecture, find refactoring opportunities, consolidate tightly-coupled modules, or make a codebase more AI-navigable.

cdcoonce/Portfolio_Website

CEO/founder-mode plan review. Rethink the problem, find the 10-star product, challenge premises, expand scope when it creates a better product. Three modes: SCOPE EXPANSION (dream big), HOLD SCOPE (maximum rigor), SCOPE REDUCTION (strip to essentials). Use when the user asks for a plan review, CEO review, mega review, or wants a plan challenged/stress-tested before implementation.

cdcoonce/Portfolio_Website

Break a PRD into independently-grabbable GitHub issues using tracer-bullet vertical slices. Use when user wants to convert a PRD to issues, create implementation tickets, or break down a PRD into work items.

cdcoonce/Portfolio_Website

Turn a PRD into a multi-phase implementation plan using tracer-bullet vertical slices, saved as a local Markdown file in docs/plans/. Use when user wants to break down a PRD, create an implementation plan, plan phases from a PRD, or mentions "tracer bullets".

cdcoonce/Portfolio_Website

Generate or update the `.claude/docs/project.md` file that gives Claude project-specific context. Use this skill when the user asks to create, update, regenerate, or refresh project context, or says things like "update project.md", "generate project context", "this repo needs a project.md", or "Claude doesn't know about this project". Also trigger when onboarding Claude to a new repository for the first time.

cdcoonce/Portfolio_Website

Generate comprehensive, high-quality README.md files for code repositories. Use this skill whenever the user asks to create, write, generate, update, or improve a README for any project or repository. Also trigger when the user says things like "document this project", "write docs for this repo", "this repo needs a README", "help me onboard developers to this codebase", or asks for project documentation in markdown. Even if the user just says "README" or "readme" in the context of a codebase, use this skill.

cdcoonce/Portfolio_Website

Create a detailed refactor plan with tiny commits via user interview, then file it as a GitHub issue. Use when user wants to plan a refactor, create a refactoring RFC, or break a refactor into safe incremental steps.

cdcoonce/Portfolio_Website

Set up pre-commit hooks for the current repo. Use when user wants to add pre-commit hooks, configure commit-time linting, formatting, type checking, or testing. Triggers on "pre-commit", "git hooks", "linting hooks", or /setup-pre-commit.

cdcoonce/Portfolio_Website

Test-driven development with red-green-refactor loop. Use when user wants to build features or fix bugs using TDD, mentions "red-green-refactor", wants integration tests, or asks for test-first development.

cdcoonce/Portfolio_Website

Triage a bug or issue by exploring the codebase to find root cause, then create a GitHub issue with a TDD-based fix plan. Use when user reports a bug, wants to file an issue, mentions "triage", or wants to investigate and plan a fix for a problem.

cdcoonce/Portfolio_Website

Rewrites the prose sections of wiki pages in-place. Reads source files to understand current context, then updates only the content inside <!-- claude:prose --> ... <!-- claude:prose:end --> markers. Never touches <!-- generated:start --> ... <!-- generated:end --> blocks. Supports targeting a single page with /update-wiki {PageName}.

cdcoonce/Portfolio_Website

Create a PRD through user interview, codebase exploration, and module design, then submit as a GitHub issue. Use when user wants to write a PRD, create a product requirements document, or plan a new feature.

相关技能