github-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitHub CLI Skill
GitHub CLI 技能
This skill provides comprehensive guidance for using the GitHub CLI () to manage repositories, CI/CD workflows, issues, pull requests, and releases.
gh本技能提供了使用GitHub CLI()管理仓库、CI/CD工作流、Issues、Pull Requests和Releases的全面指南。
ghPrerequisites
前提条件
- CLI installed and authenticated
gh - Run to verify authentication
gh auth status
- 已安装CLI并完成身份验证
gh - 运行以验证身份验证状态
gh auth status
Core Operations
核心操作
Repository Management
仓库管理
bash
undefinedbash
undefinedList repositories
List repositories
gh repo list [owner] --limit 50
gh repo list --source # Only source repos (not forks)
gh repo list --fork # Only forks
gh repo list [owner] --limit 50
gh repo list --source # Only source repos (not forks)
gh repo list --fork # Only forks
View repository
View repository
gh repo view [repo]
gh repo view --web # Open in browser
gh repo view [repo]
gh repo view --web # Open in browser
Create repository
Create repository
gh repo create <name> --public # Public repo
gh repo create <name> --private # Private repo
gh repo create <name> --clone # Create and clone locally
gh repo create <name> --template <repo> # From template
gh repo create <name> --public # Public repo
gh repo create <name> --private # Private repo
gh repo create <name> --clone # Create and clone locally
gh repo create <name> --template <repo> # From template
Clone repository
Clone repository
gh repo clone <repo>
gh repo clone <repo> -- --depth 1 # Shallow clone
gh repo clone <repo>
gh repo clone <repo> -- --depth 1 # Shallow clone
Fork repository
Fork repository
gh repo fork <repo>
gh repo fork <repo> --clone # Fork and clone
gh repo fork <repo>
gh repo fork <repo> --clone # Fork and clone
Delete repository
Delete repository
gh repo delete <repo> --yes # Requires confirmation
gh repo delete <repo> --yes # Requires confirmation
Archive/Unarchive
Archive/Unarchive
gh repo archive <repo>
gh repo unarchive <repo>
gh repo archive <repo>
gh repo unarchive <repo>
Edit repository settings
Edit repository settings
gh repo edit --default-branch main
gh repo edit --visibility public
gh repo edit --enable-issues=false
undefinedgh repo edit --default-branch main
gh repo edit --visibility public
gh repo edit --enable-issues=false
undefinedPull Requests
Pull Requests 操作
bash
undefinedbash
undefinedList PRs
List PRs
gh pr list
gh pr list --state all # All states
gh pr list --author @me # My PRs
gh pr list --search "is:open draft:false"
gh pr list
gh pr list --state all # All states
gh pr list --author @me # My PRs
gh pr list --search "is:open draft:false"
View PR
View PR
gh pr view [number]
gh pr view --web # Open in browser
gh pr view --comments # Show comments
gh pr view [number]
gh pr view --web # Open in browser
gh pr view --comments # Show comments
Create PR
Create PR
gh pr create # Interactive
gh pr create --title "Title" --body "Description"
gh pr create --draft # Create as draft
gh pr create --base main --head feature # Specify branches
gh pr create --fill # Auto-fill from commits
gh pr create # Interactive
gh pr create --title "Title" --body "Description"
gh pr create --draft # Create as draft
gh pr create --base main --head feature # Specify branches
gh pr create --fill # Auto-fill from commits
Review PR
Review PR
gh pr review [number] --approve
gh pr review [number] --request-changes --body "Comments"
gh pr review [number] --comment --body "LGTM"
gh pr review [number] --approve
gh pr review [number] --request-changes --body "Comments"
gh pr review [number] --comment --body "LGTM"
Merge PR
Merge PR
gh pr merge [number]
gh pr merge --merge # Merge commit
gh pr merge --squash # Squash and merge
gh pr merge --rebase # Rebase and merge
gh pr merge --auto # Enable auto-merge
gh pr merge --delete-branch # Delete branch after merge
gh pr merge [number]
gh pr merge --merge # Merge commit
gh pr merge --squash # Squash and merge
gh pr merge --rebase # Rebase and merge
gh pr merge --auto # Enable auto-merge
gh pr merge --delete-branch # Delete branch after merge
Other PR operations
Other PR operations
gh pr checkout [number] # Checkout PR locally
gh pr ready [number] # Mark as ready for review
gh pr close [number]
gh pr reopen [number]
gh pr diff [number]
gh pr checks [number] # View CI status
undefinedgh pr checkout [number] # Checkout PR locally
gh pr ready [number] # Mark as ready for review
gh pr close [number]
gh pr reopen [number]
gh pr diff [number]
gh pr checks [number] # View CI status
undefinedIssues
Issues 管理
bash
undefinedbash
undefinedList issues
List issues
gh issue list
gh issue list --state all
gh issue list --label "bug"
gh issue list --assignee @me
gh issue list --search "is:open label:urgent"
gh issue list
gh issue list --state all
gh issue list --label "bug"
gh issue list --assignee @me
gh issue list --search "is:open label:urgent"
View issue
View issue
gh issue view [number]
gh issue view --web
gh issue view --comments
gh issue view [number]
gh issue view --web
gh issue view --comments
Create issue
Create issue
gh issue create # Interactive
gh issue create --title "Title" --body "Description"
gh issue create --label "bug,urgent"
gh issue create --assignee "@me,user2"
gh issue create --milestone "v1.0"
gh issue create # Interactive
gh issue create --title "Title" --body "Description"
gh issue create --label "bug,urgent"
gh issue create --assignee "@me,user2"
gh issue create --milestone "v1.0"
Edit issue
Edit issue
gh issue edit [number] --title "New title"
gh issue edit [number] --add-label "priority"
gh issue edit [number] --remove-label "wontfix"
gh issue edit [number] --add-assignee "user"
gh issue edit [number] --title "New title"
gh issue edit [number] --add-label "priority"
gh issue edit [number] --remove-label "wontfix"
gh issue edit [number] --add-assignee "user"
Close/Reopen
Close/Reopen
gh issue close [number]
gh issue close [number] --reason "not planned"
gh issue reopen [number]
gh issue close [number]
gh issue close [number] --reason "not planned"
gh issue reopen [number]
Transfer issue
Transfer issue
gh issue transfer [number] <destination-repo>
gh issue transfer [number] <destination-repo>
Pin/Unpin issue
Pin/Unpin issue
gh issue pin [number]
gh issue unpin [number]
undefinedgh issue pin [number]
gh issue unpin [number]
undefinedGitHub Actions (Workflows)
GitHub Actions(工作流)
bash
undefinedbash
undefinedList workflows
List workflows
gh workflow list
gh workflow list --all # Include disabled
gh workflow list
gh workflow list --all # Include disabled
View workflow
View workflow
gh workflow view [workflow-id|name]
gh workflow view --web
gh workflow view [workflow-id|name]
gh workflow view --web
Run workflow manually
Run workflow manually
gh workflow run [workflow]
gh workflow run [workflow] --ref branch-name
gh workflow run [workflow] -f param1=value1 -f param2=value2
gh workflow run [workflow]
gh workflow run [workflow] --ref branch-name
gh workflow run [workflow] -f param1=value1 -f param2=value2
Enable/Disable workflow
Enable/Disable workflow
gh workflow enable [workflow]
gh workflow disable [workflow]
gh workflow enable [workflow]
gh workflow disable [workflow]
List workflow runs
List workflow runs
gh run list
gh run list --workflow [workflow]
gh run list --branch main
gh run list --status failure
gh run list --user @me
gh run list
gh run list --workflow [workflow]
gh run list --branch main
gh run list --status failure
gh run list --user @me
View run details
View run details
gh run view [run-id]
gh run view --web
gh run view --log # Full logs
gh run view --log-failed # Only failed job logs
gh run view [run-id]
gh run view --web
gh run view --log # Full logs
gh run view --log-failed # Only failed job logs
Watch run in progress
Watch run in progress
gh run watch [run-id]
gh run watch [run-id]
Rerun workflow
Rerun workflow
gh run rerun [run-id]
gh run rerun [run-id] --failed # Only failed jobs
gh run rerun [run-id] --debug # With debug logging
gh run rerun [run-id]
gh run rerun [run-id] --failed # Only failed jobs
gh run rerun [run-id] --debug # With debug logging
Cancel run
Cancel run
gh run cancel [run-id]
gh run cancel [run-id]
Download artifacts
Download artifacts
gh run download [run-id]
gh run download [run-id] -n artifact-name
undefinedgh run download [run-id]
gh run download [run-id] -n artifact-name
undefinedReleases
Releases 管理
bash
undefinedbash
undefinedList releases
List releases
gh release list
gh release list --exclude-drafts
gh release list
gh release list --exclude-drafts
View release
View release
gh release view [tag]
gh release view --web
gh release view [tag]
gh release view --web
Create release
Create release
gh release create <tag> # Interactive
gh release create <tag> --title "Title" --notes "Notes"
gh release create <tag> --generate-notes # Auto-generate notes
gh release create <tag> --draft # Create as draft
gh release create <tag> --prerelease # Mark as pre-release
gh release create <tag> ./dist/* # Upload assets
gh release create <tag> # Interactive
gh release create <tag> --title "Title" --notes "Notes"
gh release create <tag> --generate-notes # Auto-generate notes
gh release create <tag> --draft # Create as draft
gh release create <tag> --prerelease # Mark as pre-release
gh release create <tag> ./dist/* # Upload assets
Edit release
Edit release
gh release edit <tag> --title "New title"
gh release edit <tag> --draft=false # Publish draft
gh release edit <tag> --title "New title"
gh release edit <tag> --draft=false # Publish draft
Delete release
Delete release
gh release delete <tag>
gh release delete <tag> --cleanup-tag # Also delete tag
gh release delete <tag>
gh release delete <tag> --cleanup-tag # Also delete tag
Download assets
Download assets
gh release download <tag>
gh release download <tag> -p "*.zip" # Pattern match
gh release download <tag>
gh release download <tag> -p "*.zip" # Pattern match
Upload additional assets
Upload additional assets
gh release upload <tag> ./file.zip
undefinedgh release upload <tag> ./file.zip
undefinedGists
Gists 操作
bash
undefinedbash
undefinedList gists
List gists
gh gist list
gh gist list --public
gh gist list --secret
gh gist list
gh gist list --public
gh gist list --secret
View gist
View gist
gh gist view [gist-id]
gh gist view --web
gh gist view [gist-id]
gh gist view --web
Create gist
Create gist
gh gist create file.txt # Single file
gh gist create file1.txt file2.txt # Multiple files
gh gist create --public file.txt # Public gist
gh gist create -d "Description" file.txt
gh gist create file.txt # Single file
gh gist create file1.txt file2.txt # Multiple files
gh gist create --public file.txt # Public gist
gh gist create -d "Description" file.txt
Edit gist
Edit gist
gh gist edit [gist-id]
gh gist edit [gist-id] -a newfile.txt # Add file
gh gist edit [gist-id]
gh gist edit [gist-id] -a newfile.txt # Add file
Delete gist
Delete gist
gh gist delete [gist-id]
gh gist delete [gist-id]
Clone gist
Clone gist
gh gist clone [gist-id]
undefinedgh gist clone [gist-id]
undefinedGitHub API Direct Access
GitHub API 直接访问
bash
undefinedbash
undefinedGET request
GET request
gh api repos/{owner}/{repo}
gh api /user
gh api orgs/{org}/repos --paginate
gh api repos/{owner}/{repo}
gh api /user
gh api orgs/{org}/repos --paginate
POST request
POST request
gh api repos/{owner}/{repo}/issues -f title="Bug" -f body="Description"
gh api repos/{owner}/{repo}/issues -f title="Bug" -f body="Description"
With JSON
With JSON
gh api repos/{owner}/{repo}/labels --input data.json
gh api repos/{owner}/{repo}/labels --input data.json
GraphQL
GraphQL
gh api graphql -f query='{ viewer { login } }'
gh api graphql -f query='{ viewer { login } }'
Output formatting
Output formatting
gh api repos/{owner}/{repo} --jq '.name'
gh api repos/{owner}/{repo} -t '{{.name}}'
undefinedgh api repos/{owner}/{repo} --jq '.name'
gh api repos/{owner}/{repo} -t '{{.name}}'
undefinedLabels
标签管理
bash
undefinedbash
undefinedList labels
List labels
gh label list
gh label list
Create label
Create label
gh label create "priority:high" --color FF0000 --description "High priority"
gh label create "priority:high" --color FF0000 --description "High priority"
Edit label
Edit label
gh label edit "old-name" --name "new-name"
gh label edit "bug" --color 00FF00
gh label edit "old-name" --name "new-name"
gh label edit "bug" --color 00FF00
Delete label
Delete label
gh label delete "label-name"
gh label delete "label-name"
Clone labels from another repo
Clone labels from another repo
gh label clone source-repo
undefinedgh label clone source-repo
undefinedSSH Keys & GPG Keys
SSH 密钥与 GPG 密钥
bash
undefinedbash
undefinedList SSH keys
List SSH keys
gh ssh-key list
gh ssh-key list
Add SSH key
Add SSH key
gh ssh-key add ~/.ssh/id_rsa.pub --title "My Key"
gh ssh-key add ~/.ssh/id_rsa.pub --title "My Key"
Delete SSH key
Delete SSH key
gh ssh-key delete [key-id]
gh ssh-key delete [key-id]
List GPG keys
List GPG keys
gh gpg-key list
gh gpg-key list
Add GPG key
Add GPG key
gh gpg-key add key.gpg
undefinedgh gpg-key add key.gpg
undefinedCommon Patterns
常见使用模式
Batch Operations
批量操作
bash
undefinedbash
undefinedClose all issues with specific label
Close all issues with specific label
gh issue list --label "wontfix" --json number --jq '.[].number' |
xargs -I {} gh issue close {}
xargs -I {} gh issue close {}
gh issue list --label "wontfix" --json number --jq '.[].number' |
xargs -I {} gh issue close {}
xargs -I {} gh issue close {}
Delete all draft releases
Delete all draft releases
gh release list --json tagName,isDraft --jq '.[] | select(.isDraft) | .tagName' |
xargs -I {} gh release delete {} --yes
xargs -I {} gh release delete {} --yes
gh release list --json tagName,isDraft --jq '.[] | select(.isDraft) | .tagName' |
xargs -I {} gh release delete {} --yes
xargs -I {} gh release delete {} --yes
Approve and merge all dependabot PRs
Approve and merge all dependabot PRs
gh pr list --author "app/dependabot" --json number --jq '.[].number' |
xargs -I {} sh -c 'gh pr review {} --approve && gh pr merge {} --squash'
xargs -I {} sh -c 'gh pr review {} --approve && gh pr merge {} --squash'
undefinedgh pr list --author "app/dependabot" --json number --jq '.[].number' |
xargs -I {} sh -c 'gh pr review {} --approve && gh pr merge {} --squash'
xargs -I {} sh -c 'gh pr review {} --approve && gh pr merge {} --squash'
undefinedJSON Output and Filtering
JSON 输出与过滤
bash
undefinedbash
undefinedGet specific fields
Get specific fields
gh pr list --json number,title,author
gh issue list --json number,title,labels --jq '.[] | {num: .number, title: .title}'
gh pr list --json number,title,author
gh issue list --json number,title,labels --jq '.[] | {num: .number, title: .title}'
Filter with jq
Filter with jq
gh pr list --json number,title,mergeable --jq '.[] | select(.mergeable == "MERGEABLE")'
undefinedgh pr list --json number,title,mergeable --jq '.[] | select(.mergeable == "MERGEABLE")'
undefinedCross-Repository Operations
跨仓库操作
bash
undefinedbash
undefinedSpecify repository explicitly
Specify repository explicitly
gh pr list -R owner/repo
gh issue create -R owner/repo --title "Title"
gh workflow run -R owner/repo workflow.yml
undefinedgh pr list -R owner/repo
gh issue create -R owner/repo --title "Title"
gh workflow run -R owner/repo workflow.yml
undefinedTroubleshooting
故障排除
bash
undefinedbash
undefinedCheck authentication
Check authentication
gh auth status
gh auth status
Refresh authentication
Refresh authentication
gh auth refresh
gh auth refresh
Login with specific scopes
Login with specific scopes
gh auth login --scopes "repo,workflow,admin:org"
gh auth login --scopes "repo,workflow,admin:org"
Debug mode
Debug mode
GH_DEBUG=1 gh <command>
GH_DEBUG=1 gh <command>
Check rate limit
Check rate limit
gh api rate_limit
undefinedgh api rate_limit
undefinedReference
参考资料
For detailed command reference including all flags and options, see .
references/gh-commands.md有关包含所有标志和选项的详细命令参考,请查看。
references/gh-commands.md