github

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub CLI Skill

GitHub CLI 技能

Quick Start

快速开始

Authentication

身份验证

bash
undefined
bash
undefined

Interactive authentication (recommended)

Interactive authentication (recommended)

gh auth login
gh auth login

Check authentication status

Check authentication status

gh auth status
gh auth status

Login with token

Login with token

gh auth login --with-token < token.txt
gh auth login --with-token < token.txt

Login to enterprise

Login to enterprise

gh auth login --hostname github.example.com
undefined
gh auth login --hostname github.example.com
undefined

Configuration

配置

bash
undefined
bash
undefined

Set default editor

Set default editor

gh config set editor "code --wait"
gh config set editor "code --wait"

Set default browser

Set default browser

gh config set browser "firefox"
gh config set browser "firefox"

Set default git protocol

Set default git protocol

gh config set git_protocol ssh
gh config set git_protocol ssh

View all settings

View all settings

gh config list
undefined
gh config list
undefined

Essential Commands (Most Common First)

核心命令(按使用频率排序)

1. Issues

1. Issues

bash
undefined
bash
undefined

Create issue

Create issue

gh issue create --title "Bug: something broken" --body "Description here"
gh issue create --title "Bug: something broken" --body "Description here"

Create with labels

Create with labels

gh issue create --title "Feature request" --label "enhancement,priority:high"
gh issue create --title "Feature request" --label "enhancement,priority:high"

List issues

List issues

gh issue list # Open issues gh issue list --state all # All issues gh issue list --assignee @me # Assigned to me gh issue list --label "bug" # By label
gh issue list # Open issues gh issue list --state all # All issues gh issue list --assignee @me # Assigned to me gh issue list --label "bug" # By label

View issue

View issue

gh issue view 123 # By number gh issue view 123 --comments # With comments
gh issue view 123 # By number gh issue view 123 --comments # With comments

Edit issue

Edit issue

gh issue edit 123 --title "New title" gh issue edit 123 --add-label "in-progress" gh issue edit 123 --assignee username
gh issue edit 123 --title "New title" gh issue edit 123 --add-label "in-progress" gh issue edit 123 --assignee username

Close/reopen

Close/reopen

gh issue close 123 gh issue close 123 --comment "Fixed in PR #456" gh issue reopen 123
gh issue close 123 gh issue close 123 --comment "Fixed in PR #456" gh issue reopen 123

Comment

Comment

gh issue comment 123 --body "This is a comment"
undefined
gh issue comment 123 --body "This is a comment"
undefined

2. Pull Requests

2. Pull Requests

bash
undefined
bash
undefined

Create PR

Create PR

gh pr create --title "Feature: new thing" --body "Description" gh pr create --draft # Create as draft gh pr create --fill # Auto-fill from commits
gh pr create --title "Feature: new thing" --body "Description" gh pr create --draft # Create as draft gh pr create --fill # Auto-fill from commits

List PRs

List PRs

gh pr list # Open PRs gh pr list --state merged # Merged PRs gh pr list --author @me # My PRs gh pr list --search "review:required"
gh pr list # Open PRs gh pr list --state merged # Merged PRs gh pr list --author @me # My PRs gh pr list --search "review:required"

View PR

View PR

gh pr view 123 # By number gh pr view # Current branch PR gh pr diff 123 # View diff gh pr checks 123 # View CI status
gh pr view 123 # By number gh pr view # Current branch PR gh pr diff 123 # View diff gh pr checks 123 # View CI status

Review PRs

Review PRs

gh pr review 123 --approve gh pr review 123 --request-changes --body "Please fix X" gh pr review 123 --comment --body "Looks good overall"
gh pr review 123 --approve gh pr review 123 --request-changes --body "Please fix X" gh pr review 123 --comment --body "Looks good overall"

Merge

Merge

gh pr merge 123 # Interactive gh pr merge 123 --squash # Squash merge gh pr merge 123 --rebase # Rebase merge gh pr merge 123 --auto # Auto-merge when checks pass
gh pr merge 123 # Interactive gh pr merge 123 --squash # Squash merge gh pr merge 123 --rebase # Rebase merge gh pr merge 123 --auto # Auto-merge when checks pass

Mark ready

Mark ready

gh pr ready 123 # Convert draft to ready
gh pr ready 123 # Convert draft to ready

Comment

Comment

gh pr comment 123 --body "Comment text"
gh pr comment 123 --body "Comment text"

Close

Close

gh pr close 123
undefined
gh pr close 123
undefined

3. Repository

3. 仓库(Repository)

bash
undefined
bash
undefined

Clone

Clone

gh repo clone owner/repo gh repo clone owner/repo -- --depth 1 # Shallow clone
gh repo clone owner/repo gh repo clone owner/repo -- --depth 1 # Shallow clone

Create

Create

gh repo create my-repo --public gh repo create my-repo --private --clone
gh repo create my-repo --public gh repo create my-repo --private --clone

View

View

gh repo view # Current repo gh repo view owner/repo # Specific repo gh repo view --web # Open in browser
gh repo view # Current repo gh repo view owner/repo # Specific repo gh repo view --web # Open in browser

Fork

Fork

gh repo fork owner/repo gh repo fork owner/repo --clone # Fork and clone
gh repo fork owner/repo gh repo fork owner/repo --clone # Fork and clone

Sync fork

Sync fork

gh repo sync # Sync fork with upstream
gh repo sync # Sync fork with upstream

List repos

List repos

gh repo list # Your repos gh repo list owner # Organization repos
undefined
gh repo list # Your repos gh repo list owner # Organization repos
undefined

4. Workflow (GitHub Actions)

4. 工作流(GitHub Actions)

bash
undefined
bash
undefined

List workflows

List workflows

gh workflow list
gh workflow list

View workflow runs

View workflow runs

gh run list # Recent runs gh run list --workflow ci.yml # By workflow gh run list --status failure # Failed runs
gh run list # Recent runs gh run list --workflow ci.yml # By workflow gh run list --status failure # Failed runs

View run details

View run details

gh run view 123456 # By run ID gh run view 123456 --log # With logs gh run view 123456 --log-failed # Only failed logs
gh run view 123456 # By run ID gh run view 123456 --log # With logs gh run view 123456 --log-failed # Only failed logs

Trigger workflow

Trigger workflow

gh workflow run ci.yml gh workflow run ci.yml -f param=value
gh workflow run ci.yml gh workflow run ci.yml -f param=value

Watch run

Watch run

gh run watch # Watch current branch run gh run watch 123456 # Watch specific run
gh run watch # Watch current branch run gh run watch 123456 # Watch specific run

Cancel/rerun

Cancel/rerun

gh run cancel 123456 gh run rerun 123456 gh run rerun 123456 --failed # Rerun only failed jobs
undefined
gh run cancel 123456 gh run rerun 123456 gh run rerun 123456 --failed # Rerun only failed jobs
undefined

5. Search

5. 搜索

bash
undefined
bash
undefined

Search issues/PRs

Search issues/PRs

gh search issues "bug in:title" gh search issues "label:bug state:open" gh search prs "author:username is:merged"
gh search issues "bug in:title" gh search issues "label:bug state:open" gh search prs "author:username is:merged"

Search repos

Search repos

gh search repos "language:python stars:>1000"
gh search repos "language:python stars:>1000"

Search code

Search code

gh search code "function handleError" gh search code "filename:config.json org:myorg"
undefined
gh search code "function handleError" gh search code "filename:config.json org:myorg"
undefined

Advanced Commands

高级命令

Releases

版本发布(Releases)

bash
undefined
bash
undefined

Create release

Create release

gh release create v1.0.0 --title "Version 1.0" --notes "Release notes" gh release create v1.0.0 --generate-notes # Auto-generate notes gh release create v1.0.0 ./dist/* # Upload assets
gh release create v1.0.0 --title "Version 1.0" --notes "Release notes" gh release create v1.0.0 --generate-notes # Auto-generate notes gh release create v1.0.0 ./dist/* # Upload assets

List/view

List/view

gh release list gh release view v1.0.0
gh release list gh release view v1.0.0

Download assets

Download assets

gh release download v1.0.0 gh release download v1.0.0 --pattern "*.zip"
undefined
gh release download v1.0.0 gh release download v1.0.0 --pattern "*.zip"
undefined

Gists

Gists

bash
undefined
bash
undefined

Create gist

Create gist

gh gist create file.txt gh gist create --public file.txt gh gist create -d "Description" file1.txt file2.txt
gh gist create file.txt gh gist create --public file.txt gh gist create -d "Description" file1.txt file2.txt

List/view

List/view

gh gist list gh gist view gist_id
gh gist list gh gist view gist_id

Edit

Edit

gh gist edit gist_id
undefined
gh gist edit gist_id
undefined

API Access

API 访问

bash
undefined
bash
undefined

GraphQL query

GraphQL query

gh api graphql -f query='{ viewer { login } }'
gh api graphql -f query='{ viewer { login } }'

REST API

REST API

gh api repos/owner/repo/issues gh api repos/owner/repo/issues --method POST -f title="Issue title"
gh api repos/owner/repo/issues gh api repos/owner/repo/issues --method POST -f title="Issue title"

Paginate

Paginate

gh api repos/owner/repo/issues --paginate
undefined
gh api repos/owner/repo/issues --paginate
undefined

SSH Keys & GPG

SSH 密钥与 GPG

bash
undefined
bash
undefined

SSH keys

SSH keys

gh ssh-key add ~/.ssh/id_ed25519.pub --title "My laptop" gh ssh-key list
gh ssh-key add ~/.ssh/id_ed25519.pub --title "My laptop" gh ssh-key list

GPG keys

GPG keys

gh gpg-key add key.asc gh gpg-key list
undefined
gh gpg-key add key.asc gh gpg-key list
undefined

Common Patterns

常用使用场景

Issue-to-PR Workflow

Issue 转 PR 工作流

bash
undefined
bash
undefined

1. Create issue

1. Create issue

gh issue create --title "Feature: X" --label "enhancement"
gh issue create --title "Feature: X" --label "enhancement"

Returns issue #123

Returns issue #123

2. Create branch and work

2. Create branch and work

git checkout -b feat/issue-123-x
git checkout -b feat/issue-123-x

3. Create PR linking to issue

3. Create PR linking to issue

gh pr create --title "Feature: X" --body "Closes #123"
undefined
gh pr create --title "Feature: X" --body "Closes #123"
undefined

Code Review Flow

代码评审流程

bash
undefined
bash
undefined

Check out PR locally

Check out PR locally

gh pr checkout 456
gh pr checkout 456

Run tests, review code...

Run tests, review code...

Approve or request changes

Approve or request changes

gh pr review 456 --approve --body "LGTM!"
undefined
gh pr review 456 --approve --body "LGTM!"
undefined

CI Failure Investigation

CI 失败排查

bash
undefined
bash
undefined

List failed runs

List failed runs

gh run list --status failure
gh run list --status failure

Get logs

Get logs

gh run view RUN_ID --log-failed
gh run view RUN_ID --log-failed

Rerun after fix

Rerun after fix

gh run rerun RUN_ID
undefined
gh run rerun RUN_ID
undefined

Re-enabling GitHub MCP Server

重新启用 GitHub MCP 服务器

If you need the full GitHub MCP server for advanced operations (e.g., complex GraphQL queries, bulk operations), you can ask:
"Please use the GitHub MCP server" or "Re-enable GitHub MCP"
To re-enable manually:
  1. Edit
    ~/.copilot/github-copilot/mcp.json
  2. Remove or set
    "disabled": false
    for github-mcp-server:
json
{
  "mcpServers": {
    "github-mcp-server": {
      "disabled": false
    }
  }
}
  1. Restart the Copilot CLI session
When to use MCP vs gh CLI:
Use gh CLIUse GitHub MCP
Standard issue/PR operationsComplex multi-step GitHub operations
CI/CD workflow managementBulk operations across many repos
Quick lookups and status checksAdvanced GraphQL queries
Script automationOperations requiring persistent state
Most daily GitHub interactionsRare, specialized GitHub integrations
如果你需要使用完整的 GitHub MCP 服务器执行高级操作(例如复杂 GraphQL 查询、批量操作),你可以发起请求:
"请使用 GitHub MCP 服务器" 或 "重新启用 GitHub MCP"
手动重新启用步骤:
  1. 编辑
    ~/.copilot/github-copilot/mcp.json
  2. 移除 github-mcp-server 的
    "disabled": true
    配置,或将其改为
    "disabled": false
json
{
  "mcpServers": {
    "github-mcp-server": {
      "disabled": false
    }
  }
}
  1. 重启 Copilot CLI 会话
MCP 与 gh CLI 适用场景对比:
使用 gh CLI使用 GitHub MCP
标准 issue/PR 操作复杂多步骤 GitHub 操作
CI/CD 工作流管理跨多仓库的批量操作
快速查询与状态检查高级 GraphQL 查询
脚本自动化需要持久化状态的操作
绝大多数日常 GitHub 交互少见的、专项 GitHub 集成

Troubleshooting

故障排查

bash
undefined
bash
undefined

Check auth

Check auth

gh auth status
gh auth status

Refresh token

Refresh token

gh auth refresh
gh auth refresh

Clear cache

Clear cache

gh cache delete --all
gh cache delete --all

Debug mode

Debug mode

GH_DEBUG=api gh issue list
undefined
GH_DEBUG=api gh issue list
undefined

Environment Variables

环境变量

bash
GH_TOKEN           # Auth token (alternative to gh auth)
GH_HOST            # Default host (for enterprise)
GH_REPO            # Default repo (owner/repo format)
GH_EDITOR          # Editor for interactive commands
GH_BROWSER         # Browser for --web commands
GH_DEBUG           # Enable debug output (api, oauth)
NO_COLOR           # Disable colored output
bash
GH_TOKEN           # Auth token (alternative to gh auth)
GH_HOST            # Default host (for enterprise)
GH_REPO            # Default repo (owner/repo format)
GH_EDITOR          # Editor for interactive commands
GH_BROWSER         # Browser for --web commands
GH_DEBUG           # Enable debug output (api, oauth)
NO_COLOR           # Disable colored output