github

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub CLI Skill

GitHub CLI 技能指南

Use the
gh
CLI to interact with GitHub repositories and services.
使用
gh
命令行工具与GitHub仓库及服务进行交互。

Authentication

身份验证

Check auth status:
bash
gh auth status
Login:
bash
gh auth login
Refresh token:
bash
gh auth refresh
检查身份验证状态:
bash
gh auth status
登录:
bash
gh auth login
刷新令牌:
bash
gh auth refresh

Repositories

仓库管理

Clone repository:
bash
gh repo clone owner/repo
Create new repo:
bash
gh repo create my-repo --public --source=. --push
Fork repository:
bash
gh repo fork owner/repo --clone
View repo in browser:
bash
gh repo view --web
List your repos:
bash
gh repo list
克隆仓库:
bash
gh repo clone owner/repo
创建新仓库:
bash
gh repo create my-repo --public --source=. --push
复刻仓库:
bash
gh repo fork owner/repo --clone
在浏览器中查看仓库:
bash
gh repo view --web
列出你的仓库:
bash
gh repo list

Issues

议题管理

List issues:
bash
gh issue list
Create issue:
bash
gh issue create --title "Bug: Login fails" --body "Description here"
Create issue interactively:
bash
gh issue create
View issue:
bash
gh issue view 123
Close issue:
bash
gh issue close 123
Reopen issue:
bash
gh issue reopen 123
Comment on issue:
bash
gh issue comment 123 --body "Working on this"
Assign issue:
bash
gh issue edit 123 --add-assignee @me
Add labels:
bash
gh issue edit 123 --add-label "bug,priority:high"
列出议题:
bash
gh issue list
创建议题:
bash
gh issue create --title "Bug: 登录失败" --body "问题描述"
交互式创建议题:
bash
gh issue create
查看议题:
bash
gh issue view 123
关闭议题:
bash
gh issue close 123
重新打开议题:
bash
gh issue reopen 123
在议题下评论:
bash
gh issue comment 123 --body "正在处理此问题"
分配议题:
bash
gh issue edit 123 --add-assignee @me
添加标签:
bash
gh issue edit 123 --add-label "bug,priority:high"

Pull Requests

拉取请求管理

List PRs:
bash
gh pr list
Create PR:
bash
gh pr create --title "Add feature" --body "Description"
Create PR from current branch:
bash
gh pr create --fill
View PR:
bash
gh pr view 45
View PR in browser:
bash
gh pr view 45 --web
Checkout PR locally:
bash
gh pr checkout 45
Review PR:
bash
gh pr review 45 --approve
gh pr review 45 --request-changes --body "Please fix X"
gh pr review 45 --comment --body "Looks good but..."
Merge PR:
bash
gh pr merge 45 --squash
gh pr merge 45 --merge
gh pr merge 45 --rebase
Close PR:
bash
gh pr close 45
List PR checks:
bash
gh pr checks 45
View PR diff:
bash
gh pr diff 45
列出拉取请求:
bash
gh pr list
创建拉取请求:
bash
gh pr create --title "新增功能" --body "功能描述"
基于当前分支创建拉取请求:
bash
gh pr create --fill
查看拉取请求:
bash
gh pr view 45
在浏览器中查看拉取请求:
bash
gh pr view 45 --web
在本地检出拉取请求分支:
bash
gh pr checkout 45
审核拉取请求:
bash
gh pr review 45 --approve
gh pr review 45 --request-changes --body "请修复X问题"
gh pr review 45 --comment --body "整体不错,但有几点建议..."
合并拉取请求:
bash
gh pr merge 45 --squash
gh pr merge 45 --merge
gh pr merge 45 --rebase
关闭拉取请求:
bash
gh pr close 45
列出拉取请求检查状态:
bash
gh pr checks 45
查看拉取请求差异:
bash
gh pr diff 45

Actions (CI/CD)

Actions(CI/CD)

List workflow runs:
bash
gh run list
View run details:
bash
gh run view 12345
Watch run in progress:
bash
gh run watch 12345
View run logs:
bash
gh run view 12345 --log
Rerun failed jobs:
bash
gh run rerun 12345 --failed
List workflows:
bash
gh workflow list
Run workflow manually:
bash
gh workflow run deploy.yml
Run with inputs:
bash
gh workflow run deploy.yml -f environment=production
Disable/enable workflow:
bash
gh workflow disable deploy.yml
gh workflow enable deploy.yml
列出工作流运行记录:
bash
gh run list
查看运行详情:
bash
gh run view 12345
实时监控运行中的任务:
bash
gh run watch 12345
查看运行日志:
bash
gh run view 12345 --log
重新运行失败的任务:
bash
gh run rerun 12345 --failed
列出工作流:
bash
gh workflow list
手动触发工作流:
bash
gh workflow run deploy.yml
带参数触发工作流:
bash
gh workflow run deploy.yml -f environment=production
禁用/启用工作流:
bash
gh workflow disable deploy.yml
gh workflow enable deploy.yml

Releases

版本发布

List releases:
bash
gh release list
Create release:
bash
gh release create v1.0.0 --title "Version 1.0" --notes "Release notes"
Create from tag:
bash
gh release create v1.0.0 --generate-notes
Upload assets:
bash
gh release upload v1.0.0 ./dist/app.zip
Download assets:
bash
gh release download v1.0.0
Delete release:
bash
gh release delete v1.0.0
列出发布版本:
bash
gh release list
创建发布版本:
bash
gh release create v1.0.0 --title "版本1.0" --notes "发布说明"
基于标签创建发布版本:
bash
gh release create v1.0.0 --generate-notes
上传发布资产:
bash
gh release upload v1.0.0 ./dist/app.zip
下载发布资产:
bash
gh release download v1.0.0
删除发布版本:
bash
gh release delete v1.0.0

Gists

Gist管理

Create gist:
bash
gh gist create file.txt --public
Create from stdin:
bash
echo "Hello" | gh gist create -
List gists:
bash
gh gist list
View gist:
bash
gh gist view GIST_ID
Edit gist:
bash
gh gist edit GIST_ID
创建Gist:
bash
gh gist create file.txt --public
从标准输入创建Gist:
bash
echo "Hello" | gh gist create -
列出Gist:
bash
gh gist list
查看Gist:
bash
gh gist view GIST_ID
编辑Gist:
bash
gh gist edit GIST_ID

Search

搜索功能

Search repos:
bash
gh search repos "react hooks" --limit 10
Search issues:
bash
gh search issues "bug authentication" --repo owner/repo
Search PRs:
bash
gh search prs "fix memory leak" --state open
Search code:
bash
gh search code "function handleAuth" --repo owner/repo
搜索仓库:
bash
gh search repos "react hooks" --limit 10
搜索议题:
bash
gh search issues "bug authentication" --repo owner/repo
搜索拉取请求:
bash
gh search prs "fix memory leak" --state open
搜索代码:
bash
gh search code "function handleAuth" --repo owner/repo

API

API调用

Make API request:
bash
gh api repos/owner/repo
POST request:
bash
gh api repos/owner/repo/issues -f title="New issue" -f body="Description"
GraphQL query:
bash
gh api graphql -f query='{ viewer { login } }'
Paginate results:
bash
gh api repos/owner/repo/issues --paginate
发起API请求:
bash
gh api repos/owner/repo
POST请求:
bash
gh api repos/owner/repo/issues -f title="New issue" -f body="Description"
GraphQL查询:
bash
gh api graphql -f query='{ viewer { login } }'
分页获取结果:
bash
gh api repos/owner/repo/issues --paginate

Labels

标签管理

List labels:
bash
gh label list
Create label:
bash
gh label create "priority:high" --color FF0000 --description "High priority"
列出标签:
bash
gh label list
创建标签:
bash
gh label create "priority:high" --color FF0000 --description "高优先级"

Projects

项目管理

List projects:
bash
gh project list
View project:
bash
gh project view 1
列出项目:
bash
gh project list
查看项目:
bash
gh project view 1

SSH Keys

SSH密钥管理

List SSH keys:
bash
gh ssh-key list
Add SSH key:
bash
gh ssh-key add ~/.ssh/id_ed25519.pub --title "My laptop"
列出SSH密钥:
bash
gh ssh-key list
添加SSH密钥:
bash
gh ssh-key add ~/.ssh/id_ed25519.pub --title "我的笔记本电脑"

GPG Keys

GPG密钥管理

List GPG keys:
bash
gh gpg-key list
Add GPG key:
bash
gh gpg-key add key.gpg
列出GPG密钥:
bash
gh gpg-key list
添加GPG密钥:
bash
gh gpg-key add key.gpg

Secrets (for Actions)

Secrets(Actions专用)

List secrets:
bash
gh secret list
Set secret:
bash
gh secret set MY_SECRET
Set from file:
bash
gh secret set MY_SECRET < secret.txt
Delete secret:
bash
gh secret delete MY_SECRET
列出Secrets:
bash
gh secret list
设置Secret:
bash
gh secret set MY_SECRET
从文件设置Secret:
bash
gh secret set MY_SECRET < secret.txt
删除Secret:
bash
gh secret delete MY_SECRET

Variables (for Actions)

变量(Actions专用)

List variables:
bash
gh variable list
Set variable:
bash
gh variable set MY_VAR --body "value"
列出变量:
bash
gh variable list
设置变量:
bash
gh variable set MY_VAR --body "value"

Extensions

扩展功能

List installed extensions:
bash
gh extension list
Install extension:
bash
gh extension install owner/gh-extension
Browse extensions:
bash
gh extension browse
列出已安装的扩展:
bash
gh extension list
安装扩展:
bash
gh extension install owner/gh-extension
浏览扩展:
bash
gh extension browse

Aliases

别名设置

Create alias:
bash
gh alias set pv 'pr view'
List aliases:
bash
gh alias list
创建别名:
bash
gh alias set pv 'pr view'
列出别名:
bash
gh alias list

Configuration

配置管理

View config:
bash
gh config list
Set default editor:
bash
gh config set editor vim
Set default browser:
bash
gh config set browser "open"
查看配置:
bash
gh config list
设置默认编辑器:
bash
gh config set editor vim
设置默认浏览器:
bash
gh config set browser "open"

Common Workflows

常见工作流

Quick PR workflow:

快速拉取请求工作流:

bash
undefined
bash
undefined

Create branch, commit, push, create PR

创建分支、提交、推送、创建拉取请求

git checkout -b feature/my-feature
git checkout -b feature/my-feature

... make changes ...

... 进行代码修改 ...

git add . && git commit -m "Add feature" git push -u origin feature/my-feature gh pr create --fill
undefined
git add . && git commit -m "添加新功能" git push -u origin feature/my-feature gh pr create --fill
undefined

Review and merge:

审核与合并工作流:

bash
gh pr checkout 45
bash
gh pr checkout 45

... review code ...

... 审核代码 ...

gh pr review --approve gh pr merge --squash --delete-branch
undefined
gh pr review --approve gh pr merge --squash --delete-branch
undefined

Check CI status:

检查CI状态:

bash
gh pr checks
gh run watch
bash
gh pr checks
gh run watch