| name | gh-cli |
| description | GitHub CLI (gh) 技能。用于通过命令行与 GitHub 进行无缝交互或读取内容,包括仓库管理、PR/Issue 操作、代码空间管理、发布管理、读取 GitHub 网站内容等。当用户需要与 GitHub 仓库、PR、Issue、Release、Codespace 等交互,或读取 GitHub 网站内容,或需要执行 GitHub 相关自动化任务时使用此技能。 |
GitHub CLI (gh) 技能
GitHub CLI (gh) 是一个命令行工具,允许用户直接从终端与 GitHub 进行交互,无需切换到浏览器。
快速开始
认证
gh auth login
gh auth status
gh auth logout
核心命令概览
| 命令 | 用途 |
|---|
gh repo | 管理仓库 |
gh pr | 管理 Pull Request |
gh issue | 管理 Issue |
gh gist | 管理 Gist |
gh release | 管理发布 |
gh codespace | 管理代码空间 |
gh browse | 在浏览器中打开仓库 |
仓库管理 (gh repo)
常用操作
gh repo clone owner/repo
gh repo create my-project --public
gh repo create my-project --private --description "My new project"
gh repo list
gh repo list owner --limit 50
gh repo view owner/repo
gh repo view owner/repo --web
gh repo delete owner/repo --yes
分叉与同步
gh repo fork owner/repo
gh repo sync owner/repo
Pull Request 管理 (gh pr)
查看 PR
gh pr list
gh pr list --state merged
gh pr list --author username
gh pr list --label bug
gh pr view 123
gh pr view 123 --web
创建 PR
gh pr create
gh pr create --title "Fix bug" --body "This PR fixes..."
gh pr create --draft
PR 操作
gh pr checkout 123
gh pr merge 123
gh pr merge 123 --squash
gh pr merge 123 --rebase
gh pr close 123
gh pr reopen 123
gh pr comment 123 --body "LGTM!"
gh pr checks 123
gh pr diff 123
Issue 管理 (gh issue)
查看 Issue
gh issue list
gh issue list --state closed
gh issue list --assignee username
gh issue list --label bug
gh issue view 123
gh issue view 123 --web
创建和管理
gh issue create
gh issue create --title "Bug report" --body "Description..."
gh issue close 123
gh issue reopen 123
gh issue comment 123 --body "I can reproduce this"
gh issue edit 123 --assignee username
gh issue edit 123 --label bug --label priority-high
Gist 管理 (gh gist)
gh gist create file.txt
gh gist create file.txt --public --desc "My gist"
gh gist list
gh gist view GIST_ID
gh gist clone GIST_ID
gh gist delete GIST_ID
发布管理 (gh release)
gh release list
gh release create v1.0.0 --title "Version 1.0.0" --notes "Release notes"
gh release upload v1.0.0 ./binary.exe
gh release download v1.0.0
gh release delete v1.0.0
代码空间管理 (gh codespace)
gh codespace list
gh codespace create --repo owner/repo
gh codespace ssh
gh codespace code
gh codespace stop
gh codespace delete
GitHub Actions (gh workflow, gh run, gh cache)
工作流管理
gh workflow list
gh workflow view workflow.yml
gh workflow enable workflow.yml
gh workflow disable workflow.yml
gh workflow run workflow.yml
运行管理
gh run list
gh run list --workflow workflow.yml
gh run view RUN_ID
gh run view RUN_ID --log
gh run rerun RUN_ID
gh run rerun RUN_ID --failed
gh run cancel RUN_ID
gh run view RUN_ID --log-failed
搜索功能 (gh search)
gh search repos "query"
gh search repos --language python --stars ">100"
gh search issues "query"
gh search issues --state open --label bug
gh search prs "query"
gh search prs --state merged
gh search code "query" --repo owner/repo
常用快捷命令
gh co 123
gh browse
gh status
配置与扩展
配置管理
gh config list
gh config set editor vim
gh config set git_protocol ssh
扩展管理
gh extension list
gh extension install owner/extension
gh extension upgrade extension-name
gh extension remove extension-name
API 访问
gh api repos/owner/repo/issues
gh api repos/owner/repo/pulls --method POST --input pr.json
高级技巧
JSON 输出
gh pr list --json number,title,author,state
gh issue list --json number,title,labels --jq '.[] | select(.labels | contains(["bug"]))'
模板使用
gh pr create --template "PULL_REQUEST_TEMPLATE.md"
gh issue create --template "bug_report.md"
常见问题
认证问题
- 运行
gh auth status 检查认证状态
- 运行
gh auth login 重新登录
- 检查 SSH 密钥配置:
gh config get git_protocol
权限问题
- 确保有仓库的适当权限
- 检查 Personal Access Token 的 scopes
- 对于组织仓库,可能需要额外的组织授权
完整参考
更多详细信息,请参阅 references/commands.md 获取完整命令参考。