用途:通过 gh 命令统一完成各类 GitHub 操作,适合智能体或脚本中处理仓库、PR、Issue、代码搜索、发布与 GitHub API 调用。
主要能力:认证状态检查(gh auth status);PR 的列表、查看、diff、创建、草稿、合并、评审、CI 状态与更新分支;Issue 的列表、查看、创建、评论、关闭、编辑与搜索;仓库信息、文件读写、分支、Fork、创建仓库;代码/仓库/Issue/PR 搜索;提交历史与 diff;发布与标签;以及用 gh api 处理未覆盖的接口。
使用方式:核心原则是只请求需要的字段以节省 token,例如 gh pr view 123 --json title,state,body,url --jq '{title,state,body,url}'。常用命令包括 gh pr list --json number,title,author,updatedAt --jq '.[] | {number,title,author:.author.login}'、gh issue create --title "title" --body "description" --label "bug"、gh search code "query" --repo {owner}/{repo} --json path,repository,textMatches、gh release create {tag} --title "title" --notes "release notes"。文件内容可用 gh api repos/{owner}/{repo}/contents/{path} --jq '.content' | base64 -d 获取;多文件推送建议直接用 git。
适用场景:需要以结构化、低 token 方式在自动化流程或智能体中操作 GitHub 时。
限制:需已通过 gh auth 配置认证;输出优化依赖 --json/--jq,长输出可配合 --limit 或 | head;错误处理可用 2>/dev/null 判断命令是否成功。具体安装方式与收费信息暂未提供。