| name | GitHub CLI |
| description | "GitHub CLI (gh) 自动化操作。管理仓库、Issues、Pull Requests、Workflows、Releases 等。支持所有 gh 命令。" |
When to Use
Use this skill when you want to:
- Create, clone, or manage GitHub repositories
- Create and manage Issues and Pull Requests
- Run GitHub Actions workflows
- Create releases and manage secrets
- View repository information and statistics
Triggers:
- User says "create repo", "创建仓库", "new repository"
- User mentions "GitHub", "gh", "PR", "issue"
- User asks to "clone repo", "克隆仓库"
- User wants to "make PR", "创建 Pull Request"
Quick Start
Create a Repository
创建一个名为 my-project 的 GitHub 仓库
Clone a Repository
克隆 username/repo 到本地
Create an Issue
在 username/repo 创建一个 Issue: 添加登录功能
Create a Pull Request
为 feature-branch 创建一个 PR
Features
1. Repository Management
Create Repository
gh repo create my-project --public
gh repo create my-project --private
gh repo create my-project --description "My awesome project"
gh repo create my-project --template username/template-repo
Usage:
创建一个私有仓库,名称为 my-app
创建一个公开仓库,描述为 "A demo project"
Clone Repository
gh repo clone username/repo
gh repo clone username/repo my-local-dir
Usage:
克隆 facebook/react
克隆 username/repo 到 D:\projects\repo
List Repositories
gh repo list
gh repo list username
gh repo list --limit 30
Usage:
列出我的所有仓库
列出 microsoft 的前 20 个仓库
View Repository
gh repo view username/repo
gh repo view username/repo --web
Usage:
查看 facebook/react 的信息
在浏览器中打开我的仓库
Delete Repository
gh repo delete username/repo
Usage:
删除 my-old-project 仓库
2. Issue Management
Create Issue
gh issue create --title "Bug in login" --body "Description here"
gh issue create --title "Feature request" --label "enhancement"
gh issue create --title "Task" --assignee username
Usage:
创建一个 Issue: 标题 "修复登录Bug",内容 "用户无法登录"
创建一个带 bug 标签的 Issue
List Issues
gh issue list
gh issue list --state open
gh issue list --state closed
gh issue list --label bug
gh issue list --assignee username
Usage:
列出所有未关闭的 Issues
列出所有带 bug 标签的 Issues
View Issue
gh issue view 123
gh issue view 123 --web
Usage:
查看 Issue #123 的详细信息
Close/Reopen Issue
gh issue close 123
gh issue reopen 123
Usage:
关闭 Issue #123
重新打开 Issue #456
3. Pull Request Management
Create Pull Request
gh pr create
gh pr create --title "Add feature X" --body "Description"
gh pr create --base main
gh pr create --reviewer username
gh pr create --assignee username
gh pr create --label "enhancement"
Usage:
为当前分支创建 PR
创建一个 PR,标题 "添加登录功能",审查者 @reviewer
List Pull Requests
gh pr list
gh pr list --state open
gh pr list --state closed
gh pr list --state merged
gh pr list --author username
gh pr list --label bug
Usage:
列出所有未合并的 PRs
列出我创建的所有 PRs
View Pull Request
gh pr view 123
gh pr view 123 --web
gh pr view 123 --checks
Usage:
查看 PR #123 的详细信息
查看 PR #123 的 CI 状态
Review Pull Request
gh pr review 123 --approve
gh pr review 123 --request-changes
gh pr review 123 --comment "Looks good!"
gh pr review 123 --body "Please fix the typo"
Usage:
批准 PR #123
请求修改 PR #456
对 PR #789 添加评论
Merge Pull Request
gh pr merge 123
gh pr merge 123 --squash
gh pr merge 123 --rebase
gh pr merge 123 --delete-branch
Usage:
合并 PR #123
Squash 并合并 PR #456,然后删除分支
4. Workflow Management
List Workflows
gh workflow list
Usage:
列出所有 GitHub Actions workflows
Run Workflow
gh workflow run workflow-name
gh workflow run workflow-name -f param1=value1
gh workflow run workflow-name --ref branch-name
Usage:
运行 CI workflow
运行 deploy workflow,参数 environment=production
View Workflow Run
gh run view
gh run view run-id
gh run watch
Usage:
查看最新的 workflow 运行状态
实时查看当前运行的 workflow 日志
5. Release Management
Create Release
gh release create v1.0.0
gh release create v1.0.0 --title "Version 1.0.0" --notes "Release notes"
gh release create v1.0.0 --title "v1.0.0" dist/*
gh release create v1.0.0 --target main
Usage:
创建 v1.0.0 release
创建 v2.0.0 release,标题 "Major Update",上传 build/ 目录
List Releases
gh release list
Usage:
列出所有 releases
View Release
gh release view v1.0.0
gh release view v1.0.0 --web
Usage:
查看 v1.0.0 release 的详细信息
6. Secret Management
Set Secret
gh secret set SECRET_NAME
gh secret set SECRET_NAME < secret.txt
gh secret set SECRET_NAME --body "$MY_SECRET"
Usage:
设置 API_KEY secret
设置 DATABASE_URL secret
List Secrets
gh secret list
Usage:
列出所有 secrets
Delete Secret
gh secret delete SECRET_NAME
Usage:
删除 OLD_API_KEY secret
Advanced Usage
Batch Operations
Create Multiple Issues
while read title; do
gh issue create --title "$title" --body "Auto-created"
done < issues.txt
Usage:
批量创建 10 个 Issues
Close Multiple Issues
gh issue list --label "wontfix" --json number --jq '.[].number' | \
xargs -I {} gh issue close {}
Usage:
关闭所有带 wontfix 标签的 Issues
Automation Scripts
Auto-create PR on Branch Push
#!/bin/bash
branch=$(git rev-parse --abbrev-ref HEAD)
if [[ $branch == feature/* ]]; then
gh pr create --title "$branch" --body "Auto-created PR"
fi
Daily Report
echo "## Daily Report - $(date)"
echo "### Issues Closed"
gh issue list --state closed --limit 10
echo "### PRs Merged"
gh pr list --state merged --limit 10
Configuration
Authenticate
gh auth login
gh auth status
gh auth refresh
Set Default Repository
cd /path/to/repo
gh repo set-default username/repo
Configure Editor
gh config set editor "code --wait"
Troubleshooting
Authentication Failed
Problem: gh: authentication required
Solution:
gh auth login
Repository Not Found
Problem: Could not resolve to a Repository
Solution: Check repository name and your access permissions
Rate Limit Exceeded
Problem: API rate limit exceeded
Solution: Wait or authenticate for higher limits
Command Not Found
Problem: gh: command not found
Solution:
winget install GitHub.cli
brew install gh
sudo apt install gh
Best Practices
- Use Templates: Create issue/PR templates
- Add Labels: Use labels for organization
- Link Issues: Reference issues in PRs (#123)
- Review Before Merge: Always review code
- Use Draft PRs: For work in progress
- Delete Branches: Clean up after merge
Related Skills
git-operations - Git commands
ci-cd - Continuous integration
code-review - Code review automation
Resources