gh-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub CLI (gh)

GitHub CLI (gh)

Comprehensive reference for GitHub CLI (gh) - work seamlessly with GitHub from the command line.
Version: 2.85.0 (current as of January 2026)
GitHub CLI (gh) 全面参考指南——从命令行无缝操作GitHub。
版本: 2.85.0(截至2026年1月为最新版本)

Prerequisites

前提条件

Installation

安装

bash
undefined
bash
undefined

macOS

macOS

brew install gh
brew install gh

Linux

Linux

curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null sudo apt update sudo apt install gh
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null sudo apt update sudo apt install gh

Windows

Windows

winget install --id GitHub.cli
winget install --id GitHub.cli

Verify installation

Verify installation

gh --version
undefined
gh --version
undefined

Authentication

身份验证

bash
undefined
bash
undefined

Interactive login (default: github.com)

Interactive login (default: github.com)

gh auth login
gh auth login

Login with specific hostname

Login with specific hostname

gh auth login --hostname enterprise.internal
gh auth login --hostname enterprise.internal

Login with token

Login with token

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

Check authentication status

Check authentication status

gh auth status
gh auth status

Switch accounts

Switch accounts

gh auth switch --hostname github.com --user username
gh auth switch --hostname github.com --user username

Logout

Logout

gh auth logout --hostname github.com --user username
undefined
gh auth logout --hostname github.com --user username
undefined

Setup Git Integration

设置Git集成

bash
undefined
bash
undefined

Configure git to use gh as credential helper

Configure git to use gh as credential helper

gh auth setup-git
gh auth setup-git

View active token

View active token

gh auth token
gh auth token

Refresh authentication scopes

Refresh authentication scopes

gh auth refresh --scopes write:org,read:public_key
undefined
gh auth refresh --scopes write:org,read:public_key
undefined

CLI Structure

CLI 结构

gh                          # Root command
├── auth                    # Authentication
│   ├── login
│   ├── logout
│   ├── refresh
│   ├── setup-git
│   ├── status
│   ├── switch
│   └── token
├── browse                  # Open in browser
├── codespace               # GitHub Codespaces
│   ├── code
│   ├── cp
│   ├── create
│   ├── delete
│   ├── edit
│   ├── jupyter
│   ├── list
│   ├── logs
│   ├── ports
│   ├── rebuild
│   ├── ssh
│   ├── stop
│   └── view
├── gist                    # Gists
│   ├── clone
│   ├── create
│   ├── delete
│   ├── edit
│   ├── list
│   ├── rename
│   └── view
├── issue                   # Issues
│   ├── create
│   ├── list
│   ├── status
│   ├── close
│   ├── comment
│   ├── delete
│   ├── develop
│   ├── edit
│   ├── lock
│   ├── pin
│   ├── reopen
│   ├── transfer
│   ├── unlock
│   └── view
├── org                     # Organizations
│   └── list
├── pr                      # Pull Requests
│   ├── create
│   ├── list
│   ├── status
│   ├── checkout
│   ├── checks
│   ├── close
│   ├── comment
│   ├── diff
│   ├── edit
│   ├── lock
│   ├── merge
│   ├── ready
│   ├── reopen
│   ├── revert
│   ├── review
│   ├── unlock
│   ├── update-branch
│   └── view
├── project                 # Projects
│   ├── close
│   ├── copy
│   ├── create
│   ├── delete
│   ├── edit
│   ├── field-create
│   ├── field-delete
│   ├── field-list
│   ├── item-add
│   ├── item-archive
│   ├── item-create
│   ├── item-delete
│   ├── item-edit
│   ├── item-list
│   ├── link
│   ├── list
│   ├── mark-template
│   ├── unlink
│   └── view
├── release                 # Releases
│   ├── create
│   ├── list
│   ├── delete
│   ├── delete-asset
│   ├── download
│   ├── edit
│   ├── upload
│   ├── verify
│   ├── verify-asset
│   └── view
├── repo                    # Repositories
│   ├── create
│   ├── list
│   ├── archive
│   ├── autolink
│   ├── clone
│   ├── delete
│   ├── deploy-key
│   ├── edit
│   ├── fork
│   ├── gitignore
│   ├── license
│   ├── rename
│   ├── set-default
│   ├── sync
│   ├── unarchive
│   └── view
├── cache                   # Actions caches
│   ├── delete
│   └── list
├── run                     # Workflow runs
│   ├── cancel
│   ├── delete
│   ├── download
│   ├── list
│   ├── rerun
│   ├── view
│   └── watch
├── workflow                # Workflows
│   ├── disable
│   ├── enable
│   ├── list
│   ├── run
│   └── view
├── agent-task              # Agent tasks
├── alias                   # Command aliases
│   ├── delete
│   ├── import
│   ├── list
│   └── set
├── api                     # API requests
├── attestation             # Artifact attestations
│   ├── download
│   ├── trusted-root
│   └── verify
├── completion              # Shell completion
├── config                  # Configuration
│   ├── clear-cache
│   ├── get
│   ├── list
│   └── set
├── extension               # Extensions
│   ├── browse
│   ├── create
│   ├── exec
│   ├── install
│   ├── list
│   ├── remove
│   ├── search
│   └── upgrade
├── gpg-key                 # GPG keys
│   ├── add
│   ├── delete
│   └── list
├── label                   # Labels
│   ├── clone
│   ├── create
│   ├── delete
│   ├── edit
│   └── list
├── preview                 # Preview features
├── ruleset                 # Rulesets
│   ├── check
│   ├── list
│   └── view
├── search                  # Search
│   ├── code
│   ├── commits
│   ├── issues
│   ├── prs
│   └── repos
├── secret                  # Secrets
│   ├── delete
│   ├── list
│   └── set
├── ssh-key                 # SSH keys
│   ├── add
│   ├── delete
│   └── list
├── status                  # Status overview
└── variable                # Variables
    ├── delete
    ├── get
    ├── list
    └── set
gh                          # Root command
├── auth                    # Authentication
│   ├── login
│   ├── logout
│   ├── refresh
│   ├── setup-git
│   ├── status
│   ├── switch
│   └── token
├── browse                  # Open in browser
├── codespace               # GitHub Codespaces
│   ├── code
│   ├── cp
│   ├── create
│   ├── delete
│   ├── edit
│   ├── jupyter
│   ├── list
│   ├── logs
│   ├── ports
│   ├── rebuild
│   ├── ssh
│   ├── stop
│   └── view
├── gist                    # Gists
│   ├── clone
│   ├── create
│   ├── delete
│   ├── edit
│   ├── list
│   ├── rename
│   └── view
├── issue                   # Issues
│   ├── create
│   ├── list
│   ├── status
│   ├── close
│   ├── comment
│   ├── delete
│   ├── develop
│   ├── edit
│   ├── lock
│   ├── pin
│   ├── reopen
│   ├── transfer
│   ├── unlock
│   └── view
├── org                     # Organizations
│   └── list
├── pr                      # Pull Requests
│   ├── create
│   ├── list
│   ├── status
│   ├── checkout
│   ├── checks
│   ├── close
│   ├── comment
│   ├── diff
│   ├── edit
│   ├── lock
│   ├── merge
│   ├── ready
│   ├── reopen
│   ├── revert
│   ├── review
│   ├── unlock
│   ├── update-branch
│   └── view
├── project                 # Projects
│   ├── close
│   ├── copy
│   ├── create
│   ├── delete
│   ├── edit
│   ├── field-create
│   ├── field-delete
│   ├── field-list
│   ├── item-add
│   ├── item-archive
│   ├── item-create
│   ├── item-delete
│   ├── item-edit
│   ├── item-list
│   ├── link
│   ├── list
│   ├── mark-template
│   ├── unlink
│   └── view
├── release                 # Releases
│   ├── create
│   ├── list
│   ├── delete
│   ├── delete-asset
│   ├── download
│   ├── edit
│   ├── upload
│   ├── verify
│   ├── verify-asset
│   └── view
├── repo                    # Repositories
│   ├── create
│   ├── list
│   ├── archive
│   ├── autolink
│   ├── clone
│   ├── delete
│   ├── deploy-key
│   ├── edit
│   ├── fork
│   ├── gitignore
│   ├── license
│   ├── rename
│   ├── set-default
│   ├── sync
│   ├── unarchive
│   └── view
├── cache                   # Actions caches
│   ├── delete
│   └── list
├── run                     # Workflow runs
│   ├── cancel
│   ├── delete
│   ├── download
│   ├── list
│   ├── rerun
│   ├── view
│   └── watch
├── workflow                # Workflows
│   ├── disable
│   ├── enable
│   ├── list
│   ├── run
│   └── view
├── agent-task              # Agent tasks
├── alias                   # Command aliases
│   ├── delete
│   ├── import
│   ├── list
│   └── set
├── api                     # API requests
├── attestation             # Artifact attestations
│   ├── download
│   ├── trusted-root
│   └── verify
├── completion              # Shell completion
├── config                  # Configuration
│   ├── clear-cache
│   ├── get
│   ├── list
│   └── set
├── extension               # Extensions
│   ├── browse
│   ├── create
│   ├── exec
│   ├── install
│   ├── list
│   ├── remove
│   ├── search
│   └── upgrade
├── gpg-key                 # GPG keys
│   ├── add
│   ├── delete
│   └── list
├── label                   # Labels
│   ├── clone
│   ├── create
│   ├── delete
│   ├── edit
│   └── list
├── preview                 # Preview features
├── ruleset                 # Rulesets
│   ├── check
│   ├── list
│   └── view
├── search                  # Search
│   ├── code
│   ├── commits
│   ├── issues
│   ├── prs
│   └── repos
├── secret                  # Secrets
│   ├── delete
│   ├── list
│   └── set
├── ssh-key                 # SSH keys
│   ├── add
│   ├── delete
│   └── list
├── status                  # Status overview
└── variable                # Variables
    ├── delete
    ├── get
    ├── list
    └── set

Configuration

配置

Global Configuration

全局配置

bash
undefined
bash
undefined

List all configuration

List all configuration

gh config list
gh config list

Get specific configuration value

Get specific configuration value

gh config list git_protocol gh config get editor
gh config list git_protocol gh config get editor

Set configuration value

Set configuration value

gh config set editor vim gh config set git_protocol ssh gh config set prompt disabled gh config set pager "less -R"
gh config set editor vim gh config set git_protocol ssh gh config set prompt disabled gh config set pager "less -R"

Clear configuration cache

Clear configuration cache

gh config clear-cache
undefined
gh config clear-cache
undefined

Environment Variables

环境变量

bash
undefined
bash
undefined

GitHub token (for automation)

GitHub token (for automation)

export GH_TOKEN=ghp_xxxxxxxxxxxx
export GH_TOKEN=ghp_xxxxxxxxxxxx

GitHub hostname

GitHub hostname

export GH_HOST=github.com
export GH_HOST=github.com

Disable prompts

Disable prompts

export GH_PROMPT_DISABLED=true
export GH_PROMPT_DISABLED=true

Custom editor

Custom editor

export GH_EDITOR=vim
export GH_EDITOR=vim

Custom pager

Custom pager

export GH_PAGER=less
export GH_PAGER=less

HTTP timeout

HTTP timeout

export GH_TIMEOUT=30
export GH_TIMEOUT=30

Custom repository (override default)

Custom repository (override default)

export GH_REPO=owner/repo
export GH_REPO=owner/repo

Custom git protocol

Custom git protocol

export GH_ENTERPRISE_HOSTNAME=hostname
undefined
export GH_ENTERPRISE_HOSTNAME=hostname
undefined

Authentication (gh auth)

身份验证 (gh auth)

Login

登录

bash
undefined
bash
undefined

Interactive login

Interactive login

gh auth login
gh auth login

Web-based authentication

Web-based authentication

gh auth login --web
gh auth login --web

With clipboard for OAuth code

With clipboard for OAuth code

gh auth login --web --clipboard
gh auth login --web --clipboard

With specific git protocol

With specific git protocol

gh auth login --git-protocol ssh
gh auth login --git-protocol ssh

With custom hostname (GitHub Enterprise)

With custom hostname (GitHub Enterprise)

gh auth login --hostname enterprise.internal
gh auth login --hostname enterprise.internal

Login with token from stdin

Login with token from stdin

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

Insecure storage (plain text)

Insecure storage (plain text)

gh auth login --insecure-storage
undefined
gh auth login --insecure-storage
undefined

Status

状态

bash
undefined
bash
undefined

Show all authentication status

Show all authentication status

gh auth status
gh auth status

Show active account only

Show active account only

gh auth status --active
gh auth status --active

Show specific hostname

Show specific hostname

gh auth status --hostname github.com
gh auth status --hostname github.com

Show token in output

Show token in output

gh auth status --show-token
gh auth status --show-token

JSON output

JSON output

gh auth status --json hosts
gh auth status --json hosts

Filter with jq

Filter with jq

gh auth status --json hosts --jq '.hosts | add'
undefined
gh auth status --json hosts --jq '.hosts | add'
undefined

Switch Accounts

切换账户

bash
undefined
bash
undefined

Interactive switch

Interactive switch

gh auth switch
gh auth switch

Switch to specific user/host

Switch to specific user/host

gh auth switch --hostname github.com --user monalisa
undefined
gh auth switch --hostname github.com --user monalisa
undefined

Token

令牌

bash
undefined
bash
undefined

Print authentication token

Print authentication token

gh auth token
gh auth token

Token for specific host/user

Token for specific host/user

gh auth token --hostname github.com --user monalisa
undefined
gh auth token --hostname github.com --user monalisa
undefined

Refresh

刷新凭证

bash
undefined
bash
undefined

Refresh credentials

Refresh credentials

gh auth refresh
gh auth refresh

Add scopes

Add scopes

gh auth refresh --scopes write:org,read:public_key
gh auth refresh --scopes write:org,read:public_key

Remove scopes

Remove scopes

gh auth refresh --remove-scopes delete_repo
gh auth refresh --remove-scopes delete_repo

Reset to default scopes

Reset to default scopes

gh auth refresh --reset-scopes
gh auth refresh --reset-scopes

With clipboard

With clipboard

gh auth refresh --clipboard
undefined
gh auth refresh --clipboard
undefined

Setup Git

设置Git

bash
undefined
bash
undefined

Setup git credential helper

Setup git credential helper

gh auth setup-git
gh auth setup-git

Setup for specific host

Setup for specific host

gh auth setup-git --hostname enterprise.internal
gh auth setup-git --hostname enterprise.internal

Force setup even if host not known

Force setup even if host not known

gh auth setup-git --hostname enterprise.internal --force
undefined
gh auth setup-git --hostname enterprise.internal --force
undefined

Browse (gh browse)

浏览器打开 (gh browse)

bash
undefined
bash
undefined

Open repository in browser

Open repository in browser

gh browse
gh browse

Open specific path

Open specific path

gh browse script/ gh browse main.go:312
gh browse script/ gh browse main.go:312

Open issue or PR

Open issue or PR

gh browse 123
gh browse 123

Open commit

Open commit

gh browse 77507cd94ccafcf568f8560cfecde965fcfa63
gh browse 77507cd94ccafcf568f8560cfecde965fcfa63

Open with specific branch

Open with specific branch

gh browse main.go --branch bug-fix
gh browse main.go --branch bug-fix

Open different repository

Open different repository

gh browse --repo owner/repo
gh browse --repo owner/repo

Open specific pages

Open specific pages

gh browse --actions # Actions tab gh browse --projects # Projects tab gh browse --releases # Releases tab gh browse --settings # Settings page gh browse --wiki # Wiki page
gh browse --actions # Actions tab gh browse --projects # Projects tab gh browse --releases # Releases tab gh browse --settings # Settings page gh browse --wiki # Wiki page

Print URL instead of opening

Print URL instead of opening

gh browse --no-browser
undefined
gh browse --no-browser
undefined

Repositories (gh repo)

仓库 (gh repo)

Create Repository

创建仓库

bash
undefined
bash
undefined

Create new repository

Create new repository

gh repo create my-repo
gh repo create my-repo

Create with description

Create with description

gh repo create my-repo --description "My awesome project"
gh repo create my-repo --description "My awesome project"

Create public repository

Create public repository

gh repo create my-repo --public
gh repo create my-repo --public

Create private repository

Create private repository

gh repo create my-repo --private
gh repo create my-repo --private

Create with homepage

Create with homepage

gh repo create my-repo --homepage https://example.com
gh repo create my-repo --homepage https://example.com

Create with license

Create with license

gh repo create my-repo --license mit
gh repo create my-repo --license mit

Create with gitignore

Create with gitignore

gh repo create my-repo --gitignore python
gh repo create my-repo --gitignore python

Initialize as template repository

Initialize as template repository

gh repo create my-repo --template
gh repo create my-repo --template

Create repository in organization

Create repository in organization

gh repo create org/my-repo
gh repo create org/my-repo

Create without cloning locally

Create without cloning locally

gh repo create my-repo --source=.
gh repo create my-repo --source=.

Disable issues

Disable issues

gh repo create my-repo --disable-issues
gh repo create my-repo --disable-issues

Disable wiki

Disable wiki

gh repo create my-repo --disable-wiki
undefined
gh repo create my-repo --disable-wiki
undefined

Clone Repository

克隆仓库

bash
undefined
bash
undefined

Clone repository

Clone repository

gh repo clone owner/repo
gh repo clone owner/repo

Clone to specific directory

Clone to specific directory

gh repo clone owner/repo my-directory
gh repo clone owner/repo my-directory

Clone with different branch

Clone with different branch

gh repo clone owner/repo --branch develop
undefined
gh repo clone owner/repo --branch develop
undefined

List Repositories

列出仓库

bash
undefined
bash
undefined

List all repositories

List all repositories

gh repo list
gh repo list

List repositories for owner

List repositories for owner

gh repo list owner
gh repo list owner

Limit results

Limit results

gh repo list --limit 50
gh repo list --limit 50

Public repositories only

Public repositories only

gh repo list --public
gh repo list --public

Source repositories only (not forks)

Source repositories only (not forks)

gh repo list --source
gh repo list --source

JSON output

JSON output

gh repo list --json name,visibility,owner
gh repo list --json name,visibility,owner

Table output

Table output

gh repo list --limit 100 | tail -n +2
gh repo list --limit 100 | tail -n +2

Filter with jq

Filter with jq

gh repo list --json name --jq '.[].name'
undefined
gh repo list --json name --jq '.[].name'
undefined

View Repository

查看仓库

bash
undefined
bash
undefined

View repository details

View repository details

gh repo view
gh repo view

View specific repository

View specific repository

gh repo view owner/repo
gh repo view owner/repo

JSON output

JSON output

gh repo view --json name,description,defaultBranchRef
gh repo view --json name,description,defaultBranchRef

View in browser

View in browser

gh repo view --web
undefined
gh repo view --web
undefined

Edit Repository

编辑仓库

bash
undefined
bash
undefined

Edit description

Edit description

gh repo edit --description "New description"
gh repo edit --description "New description"

Set homepage

Set homepage

gh repo edit --homepage https://example.com
gh repo edit --homepage https://example.com

Change visibility

Change visibility

gh repo edit --visibility private gh repo edit --visibility public
gh repo edit --visibility private gh repo edit --visibility public

Enable/disable features

Enable/disable features

gh repo edit --enable-issues gh repo edit --disable-issues gh repo edit --enable-wiki gh repo edit --disable-wiki gh repo edit --enable-projects gh repo edit --disable-projects
gh repo edit --enable-issues gh repo edit --disable-issues gh repo edit --enable-wiki gh repo edit --disable-wiki gh repo edit --enable-projects gh repo edit --disable-projects

Set default branch

Set default branch

gh repo edit --default-branch main
gh repo edit --default-branch main

Rename repository

Rename repository

gh repo rename new-name
gh repo rename new-name

Archive repository

Archive repository

gh repo archive gh repo unarchive
undefined
gh repo archive gh repo unarchive
undefined

Delete Repository

删除仓库

bash
undefined
bash
undefined

Delete repository

Delete repository

gh repo delete owner/repo
gh repo delete owner/repo

Confirm without prompt

Confirm without prompt

gh repo delete owner/repo --yes
undefined
gh repo delete owner/repo --yes
undefined

Fork Repository

复刻仓库

bash
undefined
bash
undefined

Fork repository

Fork repository

gh repo fork owner/repo
gh repo fork owner/repo

Fork to organization

Fork to organization

gh repo fork owner/repo --org org-name
gh repo fork owner/repo --org org-name

Clone after forking

Clone after forking

gh repo fork owner/repo --clone
gh repo fork owner/repo --clone

Remote name for fork

Remote name for fork

gh repo fork owner/repo --remote-name upstream
undefined
gh repo fork owner/repo --remote-name upstream
undefined

Sync Fork

同步复刻仓库

bash
undefined
bash
undefined

Sync fork with upstream

Sync fork with upstream

gh repo sync
gh repo sync

Sync specific branch

Sync specific branch

gh repo sync --branch feature
gh repo sync --branch feature

Force sync

Force sync

gh repo sync --force
undefined
gh repo sync --force
undefined

Set Default Repository

设置默认仓库

bash
undefined
bash
undefined

Set default repository for current directory

Set default repository for current directory

gh repo set-default
gh repo set-default

Set default explicitly

Set default explicitly

gh repo set-default owner/repo
gh repo set-default owner/repo

Unset default

Unset default

gh repo set-default --unset
undefined
gh repo set-default --unset
undefined

Repository Autolinks

仓库自动链接

bash
undefined
bash
undefined

List autolinks

List autolinks

gh repo autolink list
gh repo autolink list

Add autolink

Add autolink

gh repo autolink add
--key-prefix JIRA-
--url-template https://jira.example.com/browse/<num>
gh repo autolink add
--key-prefix JIRA-
--url-template https://jira.example.com/browse/<num>

Delete autolink

Delete autolink

gh repo autolink delete 12345
undefined
gh repo autolink delete 12345
undefined

Repository Deploy Keys

仓库部署密钥

bash
undefined
bash
undefined

List deploy keys

List deploy keys

gh repo deploy-key list
gh repo deploy-key list

Add deploy key

Add deploy key

gh repo deploy-key add ~/.ssh/id_rsa.pub
--title "Production server"
--read-only
gh repo deploy-key add ~/.ssh/id_rsa.pub
--title "Production server"
--read-only

Delete deploy key

Delete deploy key

gh repo deploy-key delete 12345
undefined
gh repo deploy-key delete 12345
undefined

Gitignore and License

Gitignore与许可证

bash
undefined
bash
undefined

View gitignore template

View gitignore template

gh repo gitignore
gh repo gitignore

View license template

View license template

gh repo license mit
gh repo license mit

License with full name

License with full name

gh repo license mit --fullname "John Doe"
undefined
gh repo license mit --fullname "John Doe"
undefined

Issues (gh issue)

议题 (gh issue)

Create Issue

创建议题

bash
undefined
bash
undefined

Create issue interactively

Create issue interactively

gh issue create
gh issue create

Create with title

Create with title

gh issue create --title "Bug: Login not working"
gh issue create --title "Bug: Login not working"

Create with title and body

Create with title and body

gh issue create
--title "Bug: Login not working"
--body "Steps to reproduce..."
gh issue create
--title "Bug: Login not working"
--body "Steps to reproduce..."

Create with body from file

Create with body from file

gh issue create --body-file issue.md
gh issue create --body-file issue.md

Create with labels

Create with labels

gh issue create --title "Fix bug" --labels bug,high-priority
gh issue create --title "Fix bug" --labels bug,high-priority

Create with assignees

Create with assignees

gh issue create --title "Fix bug" --assignee user1,user2
gh issue create --title "Fix bug" --assignee user1,user2

Create in specific repository

Create in specific repository

gh issue create --repo owner/repo --title "Issue title"
gh issue create --repo owner/repo --title "Issue title"

Create issue from web

Create issue from web

gh issue create --web
undefined
gh issue create --web
undefined

List Issues

列出议题

bash
undefined
bash
undefined

List all open issues

List all open issues

gh issue list
gh issue list

List all issues (including closed)

List all issues (including closed)

gh issue list --state all
gh issue list --state all

List closed issues

List closed issues

gh issue list --state closed
gh issue list --state closed

Limit results

Limit results

gh issue list --limit 50
gh issue list --limit 50

Filter by assignee

Filter by assignee

gh issue list --assignee username gh issue list --assignee @me
gh issue list --assignee username gh issue list --assignee @me

Filter by labels

Filter by labels

gh issue list --labels bug,enhancement
gh issue list --labels bug,enhancement

Filter by milestone

Filter by milestone

gh issue list --milestone "v1.0"
gh issue list --milestone "v1.0"

Search/filter

Search/filter

gh issue list --search "is:open is:issue label:bug"
gh issue list --search "is:open is:issue label:bug"

JSON output

JSON output

gh issue list --json number,title,state,author
gh issue list --json number,title,state,author

Table view

Table view

gh issue list --json number,title,labels --jq '.[] | [.number, .title, .labels[].name] | @tsv'
gh issue list --json number,title,labels --jq '.[] | [.number, .title, .labels[].name] | @tsv'

Show comments count

Show comments count

gh issue list --json number,title,comments --jq '.[] | [.number, .title, .comments]'
gh issue list --json number,title,comments --jq '.[] | [.number, .title, .comments]'

Sort by

Sort by

gh issue list --sort created --order desc
undefined
gh issue list --sort created --order desc
undefined

View Issue

查看议题

bash
undefined
bash
undefined

View issue

View issue

gh issue view 123
gh issue view 123

View with comments

View with comments

gh issue view 123 --comments
gh issue view 123 --comments

View in browser

View in browser

gh issue view 123 --web
gh issue view 123 --web

JSON output

JSON output

gh issue view 123 --json title,body,state,labels,comments
gh issue view 123 --json title,body,state,labels,comments

View specific fields

View specific fields

gh issue view 123 --json title --jq '.title'
undefined
gh issue view 123 --json title --jq '.title'
undefined

Edit Issue

编辑议题

bash
undefined
bash
undefined

Edit interactively

Edit interactively

gh issue edit 123
gh issue edit 123

Edit title

Edit title

gh issue edit 123 --title "New title"
gh issue edit 123 --title "New title"

Edit body

Edit body

gh issue edit 123 --body "New description"
gh issue edit 123 --body "New description"

Add labels

Add labels

gh issue edit 123 --add-label bug,high-priority
gh issue edit 123 --add-label bug,high-priority

Remove labels

Remove labels

gh issue edit 123 --remove-label stale
gh issue edit 123 --remove-label stale

Add assignees

Add assignees

gh issue edit 123 --add-assignee user1,user2
gh issue edit 123 --add-assignee user1,user2

Remove assignees

Remove assignees

gh issue edit 123 --remove-assignee user1
gh issue edit 123 --remove-assignee user1

Set milestone

Set milestone

gh issue edit 123 --milestone "v1.0"
undefined
gh issue edit 123 --milestone "v1.0"
undefined

Close/Reopen Issue

关闭/重新打开议题

bash
undefined
bash
undefined

Close issue

Close issue

gh issue close 123
gh issue close 123

Close with comment

Close with comment

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

Reopen issue

Reopen issue

gh issue reopen 123
undefined
gh issue reopen 123
undefined

Comment on Issue

评论议题

bash
undefined
bash
undefined

Add comment

Add comment

gh issue comment 123 --body "This looks good!"
gh issue comment 123 --body "This looks good!"

Edit comment

Edit comment

gh issue comment 123 --edit 456789 --body "Updated comment"
gh issue comment 123 --edit 456789 --body "Updated comment"

Delete comment

Delete comment

gh issue comment 123 --delete 456789
undefined
gh issue comment 123 --delete 456789
undefined

Issue Status

议题状态

bash
undefined
bash
undefined

Show issue status summary

Show issue status summary

gh issue status
gh issue status

Status for specific repository

Status for specific repository

gh issue status --repo owner/repo
undefined
gh issue status --repo owner/repo
undefined

Pin/Unpin Issues

固定/取消固定议题

bash
undefined
bash
undefined

Pin issue (pinned to repo dashboard)

Pin issue (pinned to repo dashboard)

gh issue pin 123
gh issue pin 123

Unpin issue

Unpin issue

gh issue unpin 123
undefined
gh issue unpin 123
undefined

Lock/Unlock Issue

锁定/解锁议题

bash
undefined
bash
undefined

Lock conversation

Lock conversation

gh issue lock 123
gh issue lock 123

Lock with reason

Lock with reason

gh issue lock 123 --reason off-topic
gh issue lock 123 --reason off-topic

Unlock

Unlock

gh issue unlock 123
undefined
gh issue unlock 123
undefined

Transfer Issue

转移议题

bash
undefined
bash
undefined

Transfer to another repository

Transfer to another repository

gh issue transfer 123 --repo owner/new-repo
undefined
gh issue transfer 123 --repo owner/new-repo
undefined

Delete Issue

删除议题

bash
undefined
bash
undefined

Delete issue

Delete issue

gh issue delete 123
gh issue delete 123

Confirm without prompt

Confirm without prompt

gh issue delete 123 --yes
undefined
gh issue delete 123 --yes
undefined

Develop Issue (Draft PR)

基于议题开发(草稿PR)

bash
undefined
bash
undefined

Create draft PR from issue

Create draft PR from issue

gh issue develop 123
gh issue develop 123

Create in specific branch

Create in specific branch

gh issue develop 123 --branch fix/issue-123
gh issue develop 123 --branch fix/issue-123

Create with base branch

Create with base branch

gh issue develop 123 --base main
undefined
gh issue develop 123 --base main
undefined

Pull Requests (gh pr)

拉取请求 (gh pr)

Create Pull Request

创建拉取请求

bash
undefined
bash
undefined

Create PR interactively

Create PR interactively

gh pr create
gh pr create

Create with title

Create with title

gh pr create --title "Feature: Add new functionality"
gh pr create --title "Feature: Add new functionality"

Create with title and body

Create with title and body

gh pr create
--title "Feature: Add new functionality"
--body "This PR adds..."
gh pr create
--title "Feature: Add new functionality"
--body "This PR adds..."

Fill body from template

Fill body from template

gh pr create --body-file .github/PULL_REQUEST_TEMPLATE.md
gh pr create --body-file .github/PULL_REQUEST_TEMPLATE.md

Set base branch

Set base branch

gh pr create --base main
gh pr create --base main

Set head branch (default: current branch)

Set head branch (default: current branch)

gh pr create --head feature-branch
gh pr create --head feature-branch

Create draft PR

Create draft PR

gh pr create --draft
gh pr create --draft

Add assignees

Add assignees

gh pr create --assignee user1,user2
gh pr create --assignee user1,user2

Add reviewers

Add reviewers

gh pr create --reviewer user1,user2
gh pr create --reviewer user1,user2

Add labels

Add labels

gh pr create --labels enhancement,feature
gh pr create --labels enhancement,feature

Link to issue

Link to issue

gh pr create --issue 123
gh pr create --issue 123

Create in specific repository

Create in specific repository

gh pr create --repo owner/repo
gh pr create --repo owner/repo

Open in browser after creation

Open in browser after creation

gh pr create --web
undefined
gh pr create --web
undefined

List Pull Requests

列出拉取请求

bash
undefined
bash
undefined

List open PRs

List open PRs

gh pr list
gh pr list

List all PRs

List all PRs

gh pr list --state all
gh pr list --state all

List merged PRs

List merged PRs

gh pr list --state merged
gh pr list --state merged

List closed (not merged) PRs

List closed (not merged) PRs

gh pr list --state closed
gh pr list --state closed

Filter by head branch

Filter by head branch

gh pr list --head feature-branch
gh pr list --head feature-branch

Filter by base branch

Filter by base branch

gh pr list --base main
gh pr list --base main

Filter by author

Filter by author

gh pr list --author username gh pr list --author @me
gh pr list --author username gh pr list --author @me

Filter by assignee

Filter by assignee

gh pr list --assignee username
gh pr list --assignee username

Filter by labels

Filter by labels

gh pr list --labels bug,enhancement
gh pr list --labels bug,enhancement

Limit results

Limit results

gh pr list --limit 50
gh pr list --limit 50

Search

Search

gh pr list --search "is:open is:pr label:review-required"
gh pr list --search "is:open is:pr label:review-required"

JSON output

JSON output

gh pr list --json number,title,state,author,headRefName
gh pr list --json number,title,state,author,headRefName

Show check status

Show check status

gh pr list --json number,title,statusCheckRollup --jq '.[] | [.number, .title, .statusCheckRollup[]?.status]'
gh pr list --json number,title,statusCheckRollup --jq '.[] | [.number, .title, .statusCheckRollup[]?.status]'

Sort by

Sort by

gh pr list --sort created --order desc
undefined
gh pr list --sort created --order desc
undefined

View Pull Request

查看拉取请求

bash
undefined
bash
undefined

View PR

View PR

gh pr view 123
gh pr view 123

View with comments

View with comments

gh pr view 123 --comments
gh pr view 123 --comments

View in browser

View in browser

gh pr view 123 --web
gh pr view 123 --web

JSON output

JSON output

gh pr view 123 --json title,body,state,author,commits,files
gh pr view 123 --json title,body,state,author,commits,files

View diff

View diff

gh pr view 123 --json files --jq '.files[].path'
gh pr view 123 --json files --jq '.files[].path'

View with jq query

View with jq query

gh pr view 123 --json title,state --jq '"(.title): (.state)"'
undefined
gh pr view 123 --json title,state --jq '"(.title): (.state)"'
undefined

Checkout Pull Request

检出拉取请求

bash
undefined
bash
undefined

Checkout PR branch

Checkout PR branch

gh pr checkout 123
gh pr checkout 123

Checkout with specific branch name

Checkout with specific branch name

gh pr checkout 123 --branch name-123
gh pr checkout 123 --branch name-123

Force checkout

Force checkout

gh pr checkout 123 --force
undefined
gh pr checkout 123 --force
undefined

Diff Pull Request

查看拉取请求差异

bash
undefined
bash
undefined

View PR diff

View PR diff

gh pr diff 123
gh pr diff 123

View diff with color

View diff with color

gh pr diff 123 --color always
gh pr diff 123 --color always

Output to file

Output to file

gh pr diff 123 > pr-123.patch
gh pr diff 123 > pr-123.patch

View diff of specific files

View diff of specific files

gh pr diff 123 --name-only
undefined
gh pr diff 123 --name-only
undefined

Merge Pull Request

合并拉取请求

bash
undefined
bash
undefined

Merge PR

Merge PR

gh pr merge 123
gh pr merge 123

Merge with specific method

Merge with specific method

gh pr merge 123 --merge gh pr merge 123 --squash gh pr merge 123 --rebase
gh pr merge 123 --merge gh pr merge 123 --squash gh pr merge 123 --rebase

Delete branch after merge

Delete branch after merge

gh pr merge 123 --delete-branch
gh pr merge 123 --delete-branch

Merge with comment

Merge with comment

gh pr merge 123 --subject "Merge PR #123" --body "Merging feature"
gh pr merge 123 --subject "Merge PR #123" --body "Merging feature"

Merge draft PR

Merge draft PR

gh pr merge 123 --admin
gh pr merge 123 --admin

Force merge (skip checks)

Force merge (skip checks)

gh pr merge 123 --admin
undefined
gh pr merge 123 --admin
undefined

Close Pull Request

关闭拉取请求

bash
undefined
bash
undefined

Close PR (as draft, not merge)

Close PR (as draft, not merge)

gh pr close 123
gh pr close 123

Close with comment

Close with comment

gh pr close 123 --comment "Closing due to..."
undefined
gh pr close 123 --comment "Closing due to..."
undefined

Reopen Pull Request

重新打开拉取请求

bash
undefined
bash
undefined

Reopen closed PR

Reopen closed PR

gh pr reopen 123
undefined
gh pr reopen 123
undefined

Edit Pull Request

编辑拉取请求

bash
undefined
bash
undefined

Edit interactively

Edit interactively

gh pr edit 123
gh pr edit 123

Edit title

Edit title

gh pr edit 123 --title "New title"
gh pr edit 123 --title "New title"

Edit body

Edit body

gh pr edit 123 --body "New description"
gh pr edit 123 --body "New description"

Add labels

Add labels

gh pr edit 123 --add-label bug,enhancement
gh pr edit 123 --add-label bug,enhancement

Remove labels

Remove labels

gh pr edit 123 --remove-label stale
gh pr edit 123 --remove-label stale

Add assignees

Add assignees

gh pr edit 123 --add-assignee user1,user2
gh pr edit 123 --add-assignee user1,user2

Remove assignees

Remove assignees

gh pr edit 123 --remove-assignee user1
gh pr edit 123 --remove-assignee user1

Add reviewers

Add reviewers

gh pr edit 123 --add-reviewer user1,user2
gh pr edit 123 --add-reviewer user1,user2

Remove reviewers

Remove reviewers

gh pr edit 123 --remove-reviewer user1
gh pr edit 123 --remove-reviewer user1

Mark as ready for review

Mark as ready for review

gh pr edit 123 --ready
undefined
gh pr edit 123 --ready
undefined

Ready for Review

标记为可审核状态

bash
undefined
bash
undefined

Mark draft PR as ready

Mark draft PR as ready

gh pr ready 123
undefined
gh pr ready 123
undefined

Pull Request Checks

拉取请求检查

bash
undefined
bash
undefined

View PR checks

View PR checks

gh pr checks 123
gh pr checks 123

Watch checks in real-time

Watch checks in real-time

gh pr checks 123 --watch
gh pr checks 123 --watch

Watch interval (seconds)

Watch interval (seconds)

gh pr checks 123 --watch --interval 5
undefined
gh pr checks 123 --watch --interval 5
undefined

Comment on Pull Request

评论拉取请求

bash
undefined
bash
undefined

Add comment

Add comment

gh pr comment 123 --body "Looks good!"
gh pr comment 123 --body "Looks good!"

Comment on specific line

Comment on specific line

gh pr comment 123 --body "Fix this"
--repo owner/repo
--head-owner owner --head-branch feature
gh pr comment 123 --body "Fix this"
--repo owner/repo
--head-owner owner --head-branch feature

Edit comment

Edit comment

gh pr comment 123 --edit 456789 --body "Updated"
gh pr comment 123 --edit 456789 --body "Updated"

Delete comment

Delete comment

gh pr comment 123 --delete 456789
undefined
gh pr comment 123 --delete 456789
undefined

Review Pull Request

审核拉取请求

bash
undefined
bash
undefined

Review PR (opens editor)

Review PR (opens editor)

gh pr review 123
gh pr review 123

Approve PR

Approve PR

gh pr review 123 --approve
--approve-body "LGTM!"
gh pr review 123 --approve
--approve-body "LGTM!"

Request changes

Request changes

gh pr review 123 --request-changes
--body "Please fix these issues"
gh pr review 123 --request-changes
--body "Please fix these issues"

Comment on PR

Comment on PR

gh pr review 123 --comment --body "Some thoughts..."
gh pr review 123 --comment --body "Some thoughts..."

Dismiss review

Dismiss review

gh pr review 123 --dismiss
undefined
gh pr review 123 --dismiss
undefined

Update Branch

更新拉取请求分支

bash
undefined
bash
undefined

Update PR branch with latest base branch

Update PR branch with latest base branch

gh pr update-branch 123
gh pr update-branch 123

Force update

Force update

gh pr update-branch 123 --force
gh pr update-branch 123 --force

Use merge strategy

Use merge strategy

gh pr update-branch 123 --merge
undefined
gh pr update-branch 123 --merge
undefined

Lock/Unlock Pull Request

锁定/解锁拉取请求

bash
undefined
bash
undefined

Lock PR conversation

Lock PR conversation

gh pr lock 123
gh pr lock 123

Lock with reason

Lock with reason

gh pr lock 123 --reason off-topic
gh pr lock 123 --reason off-topic

Unlock

Unlock

gh pr unlock 123
undefined
gh pr unlock 123
undefined

Revert Pull Request

还原拉取请求

bash
undefined
bash
undefined

Revert merged PR

Revert merged PR

gh pr revert 123
gh pr revert 123

Revert with specific branch name

Revert with specific branch name

gh pr revert 123 --branch revert-pr-123
undefined
gh pr revert 123 --branch revert-pr-123
undefined

Pull Request Status

拉取请求状态

bash
undefined
bash
undefined

Show PR status summary

Show PR status summary

gh pr status
gh pr status

Status for specific repository

Status for specific repository

gh pr status --repo owner/repo
undefined
gh pr status --repo owner/repo
undefined

GitHub Actions

GitHub Actions

Workflow Runs (gh run)

工作流运行 (gh run)

bash
undefined
bash
undefined

List workflow runs

List workflow runs

gh run list
gh run list

List for specific workflow

List for specific workflow

gh run list --workflow "ci.yml"
gh run list --workflow "ci.yml"

List for specific branch

List for specific branch

gh run list --branch main
gh run list --branch main

Limit results

Limit results

gh run list --limit 20
gh run list --limit 20

JSON output

JSON output

gh run list --json databaseId,status,conclusion,headBranch
gh run list --json databaseId,status,conclusion,headBranch

View run details

View run details

gh run view 123456789
gh run view 123456789

View run with verbose logs

View run with verbose logs

gh run view 123456789 --log
gh run view 123456789 --log

View specific job

View specific job

gh run view 123456789 --job 987654321
gh run view 123456789 --job 987654321

View in browser

View in browser

gh run view 123456789 --web
gh run view 123456789 --web

Watch run in real-time

Watch run in real-time

gh run watch 123456789
gh run watch 123456789

Watch with interval

Watch with interval

gh run watch 123456789 --interval 5
gh run watch 123456789 --interval 5

Rerun failed run

Rerun failed run

gh run rerun 123456789
gh run rerun 123456789

Rerun specific job

Rerun specific job

gh run rerun 123456789 --job 987654321
gh run rerun 123456789 --job 987654321

Cancel run

Cancel run

gh run cancel 123456789
gh run cancel 123456789

Delete run

Delete run

gh run delete 123456789
gh run delete 123456789

Download run artifacts

Download run artifacts

gh run download 123456789
gh run download 123456789

Download specific artifact

Download specific artifact

gh run download 123456789 --name build
gh run download 123456789 --name build

Download to directory

Download to directory

gh run download 123456789 --dir ./artifacts
undefined
gh run download 123456789 --dir ./artifacts
undefined

Workflows (gh workflow)

工作流 (gh workflow)

bash
undefined
bash
undefined

List workflows

List workflows

gh workflow list
gh workflow list

View workflow details

View workflow details

gh workflow view ci.yml
gh workflow view ci.yml

View workflow YAML

View workflow YAML

gh workflow view ci.yml --yaml
gh workflow view ci.yml --yaml

View in browser

View in browser

gh workflow view ci.yml --web
gh workflow view ci.yml --web

Enable workflow

Enable workflow

gh workflow enable ci.yml
gh workflow enable ci.yml

Disable workflow

Disable workflow

gh workflow disable ci.yml
gh workflow disable ci.yml

Run workflow manually

Run workflow manually

gh workflow run ci.yml
gh workflow run ci.yml

Run with inputs

Run with inputs

gh workflow run ci.yml
--raw-field
version="1.0.0"
environment="production"
gh workflow run ci.yml
--raw-field
version="1.0.0"
environment="production"

Run from specific branch

Run from specific branch

gh workflow run ci.yml --ref develop
undefined
gh workflow run ci.yml --ref develop
undefined

Action Caches (gh cache)

操作缓存 (gh cache)

bash
undefined
bash
undefined

List caches

List caches

gh cache list
gh cache list

List for specific branch

List for specific branch

gh cache list --branch main
gh cache list --branch main

List with limit

List with limit

gh cache list --limit 50
gh cache list --limit 50

Delete cache

Delete cache

gh cache delete 123456789
gh cache delete 123456789

Delete all caches

Delete all caches

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

Action Secrets (gh secret)

操作密钥 (gh secret)

bash
undefined
bash
undefined

List secrets

List secrets

gh secret list
gh secret list

Set secret (prompts for value)

Set secret (prompts for value)

gh secret set MY_SECRET
gh secret set MY_SECRET

Set secret from environment

Set secret from environment

echo "$MY_SECRET" | gh secret set MY_SECRET
echo "$MY_SECRET" | gh secret set MY_SECRET

Set secret for specific environment

Set secret for specific environment

gh secret set MY_SECRET --env production
gh secret set MY_SECRET --env production

Set secret for organization

Set secret for organization

gh secret set MY_SECRET --org orgname
gh secret set MY_SECRET --org orgname

Delete secret

Delete secret

gh secret delete MY_SECRET
gh secret delete MY_SECRET

Delete from environment

Delete from environment

gh secret delete MY_SECRET --env production
undefined
gh secret delete MY_SECRET --env production
undefined

Action Variables (gh variable)

操作变量 (gh variable)

bash
undefined
bash
undefined

List variables

List variables

gh variable list
gh variable list

Set variable

Set variable

gh variable set MY_VAR "some-value"
gh variable set MY_VAR "some-value"

Set variable for environment

Set variable for environment

gh variable set MY_VAR "value" --env production
gh variable set MY_VAR "value" --env production

Set variable for organization

Set variable for organization

gh variable set MY_VAR "value" --org orgname
gh variable set MY_VAR "value" --org orgname

Get variable value

Get variable value

gh variable get MY_VAR
gh variable get MY_VAR

Delete variable

Delete variable

gh variable delete MY_VAR
gh variable delete MY_VAR

Delete from environment

Delete from environment

gh variable delete MY_VAR --env production
undefined
gh variable delete MY_VAR --env production
undefined

Projects (gh project)

项目 (gh project)

bash
undefined
bash
undefined

List projects

List projects

gh project list
gh project list

List for owner

List for owner

gh project list --owner owner
gh project list --owner owner

Open projects

Open projects

gh project list --open
gh project list --open

View project

View project

gh project view 123
gh project view 123

View project items

View project items

gh project view 123 --format json
gh project view 123 --format json

Create project

Create project

gh project create --title "My Project"
gh project create --title "My Project"

Create in organization

Create in organization

gh project create --title "Project" --org orgname
gh project create --title "Project" --org orgname

Create with readme

Create with readme

gh project create --title "Project" --readme "Description here"
gh project create --title "Project" --readme "Description here"

Edit project

Edit project

gh project edit 123 --title "New Title"
gh project edit 123 --title "New Title"

Delete project

Delete project

gh project delete 123
gh project delete 123

Close project

Close project

gh project close 123
gh project close 123

Copy project

Copy project

gh project copy 123 --owner target-owner --title "Copy"
gh project copy 123 --owner target-owner --title "Copy"

Mark template

Mark template

gh project mark-template 123
gh project mark-template 123

List fields

List fields

gh project field-list 123
gh project field-list 123

Create field

Create field

gh project field-create 123 --title "Status" --datatype single_select
gh project field-create 123 --title "Status" --datatype single_select

Delete field

Delete field

gh project field-delete 123 --id 456
gh project field-delete 123 --id 456

List items

List items

gh project item-list 123
gh project item-list 123

Create item

Create item

gh project item-create 123 --title "New item"
gh project item-create 123 --title "New item"

Add item to project

Add item to project

gh project item-add 123 --owner-owner --repo repo --issue 456
gh project item-add 123 --owner-owner --repo repo --issue 456

Edit item

Edit item

gh project item-edit 123 --id 456 --title "Updated title"
gh project item-edit 123 --id 456 --title "Updated title"

Delete item

Delete item

gh project item-delete 123 --id 456
gh project item-delete 123 --id 456

Archive item

Archive item

gh project item-archive 123 --id 456
gh project item-archive 123 --id 456

Link items

Link items

gh project link 123 --id 456 --link-id 789
gh project link 123 --id 456 --link-id 789

Unlink items

Unlink items

gh project unlink 123 --id 456 --link-id 789
gh project unlink 123 --id 456 --link-id 789

View project in browser

View project in browser

gh project view 123 --web
undefined
gh project view 123 --web
undefined

Releases (gh release)

发布 (gh release)

bash
undefined
bash
undefined

List releases

List releases

gh release list
gh release list

View latest release

View latest release

gh release view
gh release view

View specific release

View specific release

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

View in browser

View in browser

gh release view v1.0.0 --web
gh release view v1.0.0 --web

Create release

Create release

gh release create v1.0.0
--notes "Release notes here"
gh release create v1.0.0
--notes "Release notes here"

Create release with notes from file

Create release with notes from file

gh release create v1.0.0 --notes-file notes.md
gh release create v1.0.0 --notes-file notes.md

Create release with target

Create release with target

gh release create v1.0.0 --target main
gh release create v1.0.0 --target main

Create release as draft

Create release as draft

gh release create v1.0.0 --draft
gh release create v1.0.0 --draft

Create pre-release

Create pre-release

gh release create v1.0.0 --prerelease
gh release create v1.0.0 --prerelease

Create release with title

Create release with title

gh release create v1.0.0 --title "Version 1.0.0"
gh release create v1.0.0 --title "Version 1.0.0"

Upload asset to release

Upload asset to release

gh release upload v1.0.0 ./file.tar.gz
gh release upload v1.0.0 ./file.tar.gz

Upload multiple assets

Upload multiple assets

gh release upload v1.0.0 ./file1.tar.gz ./file2.tar.gz
gh release upload v1.0.0 ./file1.tar.gz ./file2.tar.gz

Upload with label (casing sensitive)

Upload with label (casing sensitive)

gh release upload v1.0.0 ./file.tar.gz --casing
gh release upload v1.0.0 ./file.tar.gz --casing

Delete release

Delete release

gh release delete v1.0.0
gh release delete v1.0.0

Delete with cleanup tag

Delete with cleanup tag

gh release delete v1.0.0 --yes
gh release delete v1.0.0 --yes

Delete specific asset

Delete specific asset

gh release delete-asset v1.0.0 file.tar.gz
gh release delete-asset v1.0.0 file.tar.gz

Download release assets

Download release assets

gh release download v1.0.0
gh release download v1.0.0

Download specific asset

Download specific asset

gh release download v1.0.0 --pattern "*.tar.gz"
gh release download v1.0.0 --pattern "*.tar.gz"

Download to directory

Download to directory

gh release download v1.0.0 --dir ./downloads
gh release download v1.0.0 --dir ./downloads

Download archive (zip/tar)

Download archive (zip/tar)

gh release download v1.0.0 --archive zip
gh release download v1.0.0 --archive zip

Edit release

Edit release

gh release edit v1.0.0 --notes "Updated notes"
gh release edit v1.0.0 --notes "Updated notes"

Verify release signature

Verify release signature

gh release verify v1.0.0
gh release verify v1.0.0

Verify specific asset

Verify specific asset

gh release verify-asset v1.0.0 file.tar.gz
undefined
gh release verify-asset v1.0.0 file.tar.gz
undefined

Gists (gh gist)

Gist (gh gist)

bash
undefined
bash
undefined

List gists

List gists

gh gist list
gh gist list

List all gists (including private)

List all gists (including private)

gh gist list --public
gh gist list --public

Limit results

Limit results

gh gist list --limit 20
gh gist list --limit 20

View gist

View gist

gh gist view abc123
gh gist view abc123

View gist files

View gist files

gh gist view abc123 --files
gh gist view abc123 --files

Create gist

Create gist

gh gist create script.py
gh gist create script.py

Create gist with description

Create gist with description

gh gist create script.py --desc "My script"
gh gist create script.py --desc "My script"

Create public gist

Create public gist

gh gist create script.py --public
gh gist create script.py --public

Create multi-file gist

Create multi-file gist

gh gist create file1.py file2.py
gh gist create file1.py file2.py

Create from stdin

Create from stdin

echo "print('hello')" | gh gist create
echo "print('hello')" | gh gist create

Edit gist

Edit gist

gh gist edit abc123
gh gist edit abc123

Delete gist

Delete gist

gh gist delete abc123
gh gist delete abc123

Rename gist file

Rename gist file

gh gist rename abc123 --filename old.py new.py
gh gist rename abc123 --filename old.py new.py

Clone gist

Clone gist

gh gist clone abc123
gh gist clone abc123

Clone to directory

Clone to directory

gh gist clone abc123 my-directory
undefined
gh gist clone abc123 my-directory
undefined

Codespaces (gh codespace)

Codespaces (gh codespace)

bash
undefined
bash
undefined

List codespaces

List codespaces

gh codespace list
gh codespace list

Create codespace

Create codespace

gh codespace create
gh codespace create

Create with specific repository

Create with specific repository

gh codespace create --repo owner/repo
gh codespace create --repo owner/repo

Create with branch

Create with branch

gh codespace create --branch develop
gh codespace create --branch develop

Create with specific machine

Create with specific machine

gh codespace create --machine premiumLinux
gh codespace create --machine premiumLinux

View codespace details

View codespace details

gh codespace view
gh codespace view

SSH into codespace

SSH into codespace

gh codespace ssh
gh codespace ssh

SSH with specific command

SSH with specific command

gh codespace ssh --command "cd /workspaces && ls"
gh codespace ssh --command "cd /workspaces && ls"

Open codespace in browser

Open codespace in browser

gh codespace code
gh codespace code

Open in VS Code

Open in VS Code

gh codespace code --codec
gh codespace code --codec

Open with specific path

Open with specific path

gh codespace code --path /workspaces/repo
gh codespace code --path /workspaces/repo

Stop codespace

Stop codespace

gh codespace stop
gh codespace stop

Delete codespace

Delete codespace

gh codespace delete
gh codespace delete

View logs

View logs

gh codespace logs
--tail 100
gh codespace logs
--tail 100

View ports

View ports

gh codespace ports
gh codespace ports

Forward port

Forward port

gh codespace cp 8080:8080
gh codespace cp 8080:8080

Rebuild codespace

Rebuild codespace

gh codespace rebuild
gh codespace rebuild

Edit codespace

Edit codespace

gh codespace edit --machine standardLinux
gh codespace edit --machine standardLinux

Jupyter support

Jupyter support

gh codespace jupyter
gh codespace jupyter

Copy files to/from codespace

Copy files to/from codespace

gh codespace cp file.txt :/workspaces/file.txt gh codespace cp :/workspaces/file.txt ./file.txt
undefined
gh codespace cp file.txt :/workspaces/file.txt gh codespace cp :/workspaces/file.txt ./file.txt
undefined

Organizations (gh org)

组织 (gh org)

bash
undefined
bash
undefined

List organizations

List organizations

gh org list
gh org list

List for user

List for user

gh org list --user username
gh org list --user username

JSON output

JSON output

gh org list --json login,name,description
gh org list --json login,name,description

View organization

View organization

gh org view orgname
gh org view orgname

View organization members

View organization members

gh org view orgname --json members --jq '.members[] | .login'
undefined
gh org view orgname --json members --jq '.members[] | .login'
undefined

Search (gh search)

搜索 (gh search)

bash
undefined
bash
undefined

Search code

Search code

gh search code "TODO"
gh search code "TODO"

Search in specific repository

Search in specific repository

gh search code "TODO" --repo owner/repo
gh search code "TODO" --repo owner/repo

Search commits

Search commits

gh search commits "fix bug"
gh search commits "fix bug"

Search issues

Search issues

gh search issues "label:bug state:open"
gh search issues "label:bug state:open"

Search PRs

Search PRs

gh search prs "is:open is:pr review:required"
gh search prs "is:open is:pr review:required"

Search repositories

Search repositories

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

Limit results

Limit results

gh search repos "topic:api" --limit 50
gh search repos "topic:api" --limit 50

JSON output

JSON output

gh search repos "stars:>100" --json name,description,stargazers
gh search repos "stars:>100" --json name,description,stargazers

Order results

Order results

gh search repos "language:rust" --order desc --sort stars
gh search repos "language:rust" --order desc --sort stars

Search with extensions

Search with extensions

gh search code "import" --extension py
gh search code "import" --extension py

Web search (open in browser)

Web search (open in browser)

gh search prs "is:open" --web
undefined
gh search prs "is:open" --web
undefined

Labels (gh label)

标签 (gh label)

bash
undefined
bash
undefined

List labels

List labels

gh label list
gh label list

Create label

Create label

gh label create bug --color "d73a4a" --description "Something isn't working"
gh label create bug --color "d73a4a" --description "Something isn't working"

Create with hex color

Create with hex color

gh label create enhancement --color "#a2eeef"
gh label create enhancement --color "#a2eeef"

Edit label

Edit label

gh label edit bug --name "bug-report" --color "ff0000"
gh label edit bug --name "bug-report" --color "ff0000"

Delete label

Delete label

gh label delete bug
gh label delete bug

Clone labels from repository

Clone labels from repository

gh label clone owner/repo
gh label clone owner/repo

Clone to specific repository

Clone to specific repository

gh label clone owner/repo --repo target/repo
undefined
gh label clone owner/repo --repo target/repo
undefined

SSH Keys (gh ssh-key)

SSH密钥 (gh ssh-key)

bash
undefined
bash
undefined

List 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 laptop"
gh ssh-key add ~/.ssh/id_rsa.pub --title "My laptop"

Add key with type

Add key with type

gh ssh-key add ~/.ssh/id_ed25519.pub --type "authentication"
gh ssh-key add ~/.ssh/id_ed25519.pub --type "authentication"

Delete SSH key

Delete SSH key

gh ssh-key delete 12345
gh ssh-key delete 12345

Delete by title

Delete by title

gh ssh-key delete --title "My laptop"
undefined
gh ssh-key delete --title "My laptop"
undefined

GPG Keys (gh gpg-key)

GPG密钥 (gh gpg-key)

bash
undefined
bash
undefined

List GPG keys

List GPG keys

gh gpg-key list
gh gpg-key list

Add GPG key

Add GPG key

gh gpg-key add ~/.ssh/id_rsa.pub
gh gpg-key add ~/.ssh/id_rsa.pub

Delete GPG key

Delete GPG key

gh gpg-key delete 12345
gh gpg-key delete 12345

Delete by key ID

Delete by key ID

gh gpg-key delete ABCD1234
undefined
gh gpg-key delete ABCD1234
undefined

Status (gh status)

状态 (gh status)

bash
undefined
bash
undefined

Show status overview

Show status overview

gh status
gh status

Status for specific repositories

Status for specific repositories

gh status --repo owner/repo
gh status --repo owner/repo

JSON output

JSON output

gh status --json
undefined
gh status --json
undefined

Configuration (gh config)

配置 (gh config)

bash
undefined
bash
undefined

List all config

List all config

gh config list
gh config list

Get specific value

Get specific value

gh config get editor
gh config get editor

Set value

Set value

gh config set editor vim
gh config set editor vim

Set git protocol

Set git protocol

gh config set git_protocol ssh
gh config set git_protocol ssh

Clear cache

Clear cache

gh config clear-cache
gh config clear-cache

Set prompt behavior

Set prompt behavior

gh config set prompt disabled gh config set prompt enabled
undefined
gh config set prompt disabled gh config set prompt enabled
undefined

Extensions (gh extension)

扩展 (gh extension)

bash
undefined
bash
undefined

List installed extensions

List installed extensions

gh extension list
gh extension list

Search extensions

Search extensions

gh extension search github
gh extension search github

Install extension

Install extension

gh extension install owner/extension-repo
gh extension install owner/extension-repo

Install from branch

Install from branch

gh extension install owner/extension-repo --branch develop
gh extension install owner/extension-repo --branch develop

Upgrade extension

Upgrade extension

gh extension upgrade extension-name
gh extension upgrade extension-name

Remove extension

Remove extension

gh extension remove extension-name
gh extension remove extension-name

Create new extension

Create new extension

gh extension create my-extension
gh extension create my-extension

Browse extensions

Browse extensions

gh extension browse
gh extension browse

Execute extension command

Execute extension command

gh extension exec my-extension --arg value
undefined
gh extension exec my-extension --arg value
undefined

Aliases (gh alias)

别名 (gh alias)

bash
undefined
bash
undefined

List aliases

List aliases

gh alias list
gh alias list

Set alias

Set alias

gh alias set prview 'pr view --web'
gh alias set prview 'pr view --web'

Set shell alias

Set shell alias

gh alias set co 'pr checkout' --shell
gh alias set co 'pr checkout' --shell

Delete alias

Delete alias

gh alias delete prview
gh alias delete prview

Import aliases

Import aliases

gh alias import ./aliases.sh
undefined
gh alias import ./aliases.sh
undefined

API Requests (gh api)

API请求 (gh api)

bash
undefined
bash
undefined

Make API request

Make API request

gh api /user
gh api /user

Request with method

Request with method

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

Request with headers

Request with headers

gh api /user
--header "Accept: application/vnd.github.v3+json"
gh api /user
--header "Accept: application/vnd.github.v3+json"

Request with pagination

Request with pagination

gh api /user/repos --paginate
gh api /user/repos --paginate

Raw output (no formatting)

Raw output (no formatting)

gh api /user --raw
gh api /user --raw

Include headers in output

Include headers in output

gh api /user --include
gh api /user --include

Silent mode (no progress output)

Silent mode (no progress output)

gh api /user --silent
gh api /user --silent

Input from file

Input from file

gh api --input request.json
gh api --input request.json

jq query on response

jq query on response

gh api /user --jq '.login'
gh api /user --jq '.login'

Field from response

Field from response

gh api /repos/owner/repo --jq '.stargazers_count'
gh api /repos/owner/repo --jq '.stargazers_count'

GitHub Enterprise

GitHub Enterprise

gh api /user --hostname enterprise.internal
gh api /user --hostname enterprise.internal

GraphQL query

GraphQL query

gh api graphql
-f query=' { viewer { login repositories(first: 5) { nodes { name } } } }'
undefined
gh api graphql
-f query=' { viewer { login repositories(first: 5) { nodes { name } } } }'
undefined

Rulesets (gh ruleset)

规则集 (gh ruleset)

bash
undefined
bash
undefined

List rulesets

List rulesets

gh ruleset list
gh ruleset list

View ruleset

View ruleset

gh ruleset view 123
gh ruleset view 123

Check ruleset

Check ruleset

gh ruleset check --branch feature
gh ruleset check --branch feature

Check specific repository

Check specific repository

gh ruleset check --repo owner/repo --branch main
undefined
gh ruleset check --repo owner/repo --branch main
undefined

Attestations (gh attestation)

证明 (gh attestation)

bash
undefined
bash
undefined

Download attestation

Download attestation

gh attestation download owner/repo
--artifact-id 123456
gh attestation download owner/repo
--artifact-id 123456

Verify attestation

Verify attestation

gh attestation verify owner/repo
gh attestation verify owner/repo

Get trusted root

Get trusted root

gh attestation trusted-root
undefined
gh attestation trusted-root
undefined

Completion (gh completion)

补全 (gh completion)

bash
undefined
bash
undefined

Generate shell completion

Generate shell completion

gh completion -s bash > ~/.gh-complete.bash gh completion -s zsh > ~/.gh-complete.zsh gh completion -s fish > ~/.gh-complete.fish gh completion -s powershell > ~/.gh-complete.ps1
gh completion -s bash > ~/.gh-complete.bash gh completion -s zsh > ~/.gh-complete.zsh gh completion -s fish > ~/.gh-complete.fish gh completion -s powershell > ~/.gh-complete.ps1

Shell-specific instructions

Shell-specific instructions

gh completion --shell=bash gh completion --shell=zsh
undefined
gh completion --shell=bash gh completion --shell=zsh
undefined

Preview (gh preview)

预览 (gh preview)

bash
undefined
bash
undefined

List preview features

List preview features

gh preview
gh preview

Run preview script

Run preview script

gh preview prompter
undefined
gh preview prompter
undefined

Agent Tasks (gh agent-task)

Agent任务 (gh agent-task)

bash
undefined
bash
undefined

List agent tasks

List agent tasks

gh agent-task list
gh agent-task list

View agent task

View agent task

gh agent-task view 123
gh agent-task view 123

Create agent task

Create agent task

gh agent-task create --description "My task"
undefined
gh agent-task create --description "My task"
undefined

Global Flags

全局标志

FlagDescription
--help
/
-h
Show help for command
--version
Show gh version
--repo [HOST/]OWNER/REPO
Select another repository
--hostname HOST
GitHub hostname
--jq EXPRESSION
Filter JSON output
--json FIELDS
Output JSON with specified fields
--template STRING
Format JSON using Go template
--web
Open in browser
--paginate
Make additional API calls
--verbose
Show verbose output
--debug
Show debug output
--timeout SECONDS
Maximum API request duration
--cache CACHE
Cache control (default, force, bypass)
Flag描述
--help
/
-h
显示命令帮助
--version
显示gh版本
--repo [HOST/]OWNER/REPO
选择其他仓库
--hostname HOST
GitHub主机名
--jq EXPRESSION
过滤JSON输出
--json FIELDS
输出包含指定字段的JSON
--template STRING
使用Go模板格式化JSON
--web
在浏览器中打开
--paginate
发起额外的API请求以获取更多结果
--verbose
显示详细输出
--debug
显示调试输出
--timeout SECONDS
API请求的最长持续时间
--cache CACHE
缓存控制(默认、强制、绕过)

Output Formatting

输出格式化

JSON Output

JSON输出

bash
undefined
bash
undefined

Basic JSON

Basic JSON

gh repo view --json name,description
gh repo view --json name,description

Nested fields

Nested fields

gh repo view --json owner,name --jq '.owner.login + "/" + .name'
gh repo view --json owner,name --jq '.owner.login + "/" + .name'

Array operations

Array operations

gh pr list --json number,title --jq '.[] | select(.number > 100)'
gh pr list --json number,title --jq '.[] | select(.number > 100)'

Complex queries

Complex queries

gh issue list --json number,title,labels
--jq '.[] | {number, title: .title, tags: [.labels[].name]}'
undefined
gh issue list --json number,title,labels
--jq '.[] | {number, title: .title, tags: [.labels[].name]}'
undefined

Template Output

模板输出

bash
undefined
bash
undefined

Custom template

Custom template

gh repo view
--template '{{.name}}: {{.description}}'
gh repo view
--template '{{.name}}: {{.description}}'

Multiline template

Multiline template

gh pr view 123
--template 'Title: {{.title}} Author: {{.author.login}} State: {{.state}} '
undefined
gh pr view 123
--template 'Title: {{.title}} Author: {{.author.login}} State: {{.state}} '
undefined

Common Workflows

常见工作流

Create PR from Issue

基于议题创建拉取请求

bash
undefined
bash
undefined

Create branch from issue

Create branch from issue

gh issue develop 123 --branch feature/issue-123
gh issue develop 123 --branch feature/issue-123

Make changes, commit, push

Make changes, commit, push

git add . git commit -m "Fix issue #123" git push
git add . git commit -m "Fix issue #123" git push

Create PR linking to issue

Create PR linking to issue

gh pr create --title "Fix #123" --body "Closes #123"
undefined
gh pr create --title "Fix #123" --body "Closes #123"
undefined

Bulk Operations

批量操作

bash
undefined
bash
undefined

Close multiple issues

Close multiple issues

gh issue list --search "label:stale"
--json number
--jq '.[].number' |
xargs -I {} gh issue close {} --comment "Closing as stale"
gh issue list --search "label:stale"
--json number
--jq '.[].number' |
xargs -I {} gh issue close {} --comment "Closing as stale"

Add label to multiple PRs

Add label to multiple PRs

gh pr list --search "review:required"
--json number
--jq '.[].number' |
xargs -I {} gh pr edit {} --add-label needs-review
undefined
gh pr list --search "review:required"
--json number
--jq '.[].number' |
xargs -I {} gh pr edit {} --add-label needs-review
undefined

Repository Setup Workflow

仓库设置工作流

bash
undefined
bash
undefined

Create repository with initial setup

Create repository with initial setup

gh repo create my-project --public
--description "My awesome project"
--clone
--gitignore python
--license mit
cd my-project
gh repo create my-project --public
--description "My awesome project"
--clone
--gitignore python
--license mit
cd my-project

Set up branches

Set up branches

git checkout -b develop git push -u origin develop
git checkout -b develop git push -u origin develop

Create labels

Create labels

gh label create bug --color "d73a4a" --description "Bug report" gh label create enhancement --color "a2eeef" --description "Feature request" gh label create documentation --color "0075ca" --description "Documentation"
undefined
gh label create bug --color "d73a4a" --description "Bug report" gh label create enhancement --color "a2eeef" --description "Feature request" gh label create documentation --color "0075ca" --description "Documentation"
undefined

CI/CD Workflow

CI/CD工作流

bash
undefined
bash
undefined

Run workflow and wait

Run workflow and wait

RUN_ID=$(gh workflow run ci.yml --ref main --jq '.databaseId')
RUN_ID=$(gh workflow run ci.yml --ref main --jq '.databaseId')

Watch the run

Watch the run

gh run watch "$RUN_ID"
gh run watch "$RUN_ID"

Download artifacts on completion

Download artifacts on completion

gh run download "$RUN_ID" --dir ./artifacts
undefined
gh run download "$RUN_ID" --dir ./artifacts
undefined

Fork Sync Workflow

复刻仓库同步工作流

bash
undefined
bash
undefined

Fork repository

Fork repository

gh repo fork original/repo --clone
cd repo
gh repo fork original/repo --clone
cd repo

Add upstream remote

Add upstream remote

git remote add upstream https://github.com/original/repo.git
git remote add upstream https://github.com/original/repo.git

Sync fork

Sync fork

gh repo sync
gh repo sync

Or manual sync

Or manual sync

git fetch upstream git checkout main git merge upstream/main git push origin main
undefined
git fetch upstream git checkout main git merge upstream/main git push origin main
undefined

Environment Setup

环境设置

Shell Integration

Shell集成

bash
undefined
bash
undefined

Add to ~/.bashrc or ~/.zshrc

Add to ~/.bashrc or ~/.zshrc

eval "$(gh completion -s bash)" # or zsh/fish
eval "$(gh completion -s bash)" # or zsh/fish

Create useful aliases

Create useful aliases

alias gs='gh status' alias gpr='gh pr view --web' alias gir='gh issue view --web' alias gco='gh pr checkout'
undefined
alias gs='gh status' alias gpr='gh pr view --web' alias gir='gh issue view --web' alias gco='gh pr checkout'
undefined

Git Configuration

Git配置

bash
undefined
bash
undefined

Use gh as credential helper

Use gh as credential helper

gh auth setup-git
gh auth setup-git

Set gh as default for repo operations

Set gh as default for repo operations

git config --global credential.helper 'gh !gh auth setup-git'
git config --global credential.helper 'gh !gh auth setup-git'

Or manually

Or manually

git config --global credential.helper github
undefined
git config --global credential.helper github
undefined

Best Practices

最佳实践

  1. Authentication: Use environment variables for automation
    bash
    export GH_TOKEN=$(gh auth token)
  2. Default Repository: Set default to avoid repetition
    bash
    gh repo set-default owner/repo
  3. JSON Parsing: Use jq for complex data extraction
    bash
    gh pr list --json number,title --jq '.[] | select(.title | contains("fix"))'
  4. Pagination: Use --paginate for large result sets
    bash
    gh issue list --state all --paginate
  5. Caching: Use cache control for frequently accessed data
    bash
    gh api /user --cache force
  1. 身份验证:自动化场景下使用环境变量
    bash
    export GH_TOKEN=$(gh auth token)
  2. 默认仓库:设置默认仓库以避免重复输入
    bash
    gh repo set-default owner/repo
  3. JSON解析:使用jq进行复杂数据提取
    bash
    gh pr list --json number,title --jq '.[] | select(.title | contains("fix"))'
  4. 分页:对大型结果集使用--paginate参数
    bash
    gh issue list --state all --paginate
  5. 缓存:对频繁访问的数据使用缓存控制
    bash
    gh api /user --cache force

Getting Help

获取帮助

bash
undefined
bash
undefined

General help

General help

gh --help
gh --help

Command help

Command help

gh pr --help gh issue create --help
gh pr --help gh issue create --help

Help topics

Help topics

gh help formatting gh help environment gh help exit-codes gh help accessibility
undefined
gh help formatting gh help environment gh help exit-codes gh help accessibility
undefined

References

参考资料