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月为最新版本)
winget install --id GitHub.cli
winget install --id GitHub.cli
Verify installation
Verify installation
Interactive login (default: github.com)
Interactive login (default: github.com)
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
Switch accounts
Switch accounts
gh auth switch --hostname github.com --user username
gh auth switch --hostname github.com --user username
gh auth logout --hostname github.com --user username
gh auth logout --hostname github.com --user username
Setup Git Integration
设置Git集成
Configure git to use gh as credential helper
Configure git to use gh as credential helper
View active token
View active token
Refresh authentication scopes
Refresh authentication scopes
gh auth refresh --scopes write:org,read:public_key
gh auth refresh --scopes write:org,read:public_key
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
List all configuration
List all configuration
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
Environment Variables
环境变量
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
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
export GH_ENTERPRISE_HOSTNAME=hostname
Authentication (gh auth)
身份验证 (gh auth)
Interactive login
Interactive login
Web-based authentication
Web-based authentication
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
gh auth login --insecure-storage
Show all authentication status
Show all authentication status
Show active account only
Show active account only
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
gh auth status --json hosts
gh auth status --json hosts
Filter with jq
Filter with jq
gh auth status --json hosts --jq '.hosts | add'
gh auth status --json hosts --jq '.hosts | add'
Interactive switch
Interactive switch
Switch to specific user/host
Switch to specific user/host
gh auth switch --hostname github.com --user monalisa
gh auth switch --hostname github.com --user monalisa
Print authentication token
Print authentication token
Token for specific host/user
Token for specific host/user
gh auth token --hostname github.com --user monalisa
gh auth token --hostname github.com --user monalisa
Refresh credentials
Refresh credentials
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
gh auth refresh --clipboard
Setup git credential helper
Setup git credential helper
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
gh auth setup-git --hostname enterprise.internal --force
Browse (gh browse)
浏览器打开 (gh browse)
Open repository in browser
Open repository in browser
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 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
Repositories (gh repo)
仓库 (gh repo)
Create new repository
Create new repository
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
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
gh repo create my-repo --disable-wiki
gh repo create my-repo --disable-wiki
Clone repository
Clone repository
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
gh repo clone owner/repo --branch develop
List all repositories
List all repositories
List repositories for owner
List repositories for owner
Limit results
Limit results
Public repositories only
Public repositories only
Source repositories only (not forks)
Source repositories only (not forks)
gh repo list --json name,visibility,owner
gh repo list --json name,visibility,owner
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'
gh repo list --json name --jq '.[].name'
View repository details
View repository details
View specific repository
View specific repository
gh repo view --json name,description,defaultBranchRef
gh repo view --json name,description,defaultBranchRef
View in browser
View in browser
Edit description
Edit description
gh repo edit --description "New description"
gh repo edit --description "New description"
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
Archive repository
Archive repository
gh repo archive
gh repo unarchive
gh repo archive
gh repo unarchive
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
gh repo delete owner/repo --yes
Fork repository
Fork repository
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
gh repo fork owner/repo --remote-name upstream
Sync fork with upstream
Sync fork with upstream
Sync specific branch
Sync specific branch
gh repo sync --branch feature
gh repo sync --branch feature
Set Default Repository
设置默认仓库
Set default repository for current directory
Set default repository for current directory
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
gh repo set-default --unset
Repository Autolinks
仓库自动链接
List autolinks
List autolinks
Delete autolink
Delete autolink
gh repo autolink delete 12345
gh repo autolink delete 12345
Repository Deploy Keys
仓库部署密钥
List deploy keys
List deploy keys
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
gh repo deploy-key delete 12345
Gitignore and License
Gitignore与许可证
View gitignore template
View gitignore template
View license template
View license template
License with full name
License with full name
gh repo license mit --fullname "John Doe"
gh repo license mit --fullname "John Doe"
Issues (gh issue)
议题 (gh issue)
Create issue interactively
Create issue interactively
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
List all open issues
List all open issues
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
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"
gh issue list --json number,title,state,author
gh issue list --json number,title,state,author
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]'
gh issue list --sort created --order desc
gh issue list --sort created --order desc
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 --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'
gh issue view 123 --json title --jq '.title'
Edit interactively
Edit interactively
gh issue edit 123 --title "New title"
gh issue edit 123 --title "New title"
gh issue edit 123 --body "New description"
gh issue edit 123 --body "New description"
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"
gh issue edit 123 --milestone "v1.0"
Close/Reopen Issue
关闭/重新打开议题
Close with comment
Close with comment
gh issue close 123 --comment "Fixed in PR #456"
gh issue close 123 --comment "Fixed in PR #456"
gh issue comment 123 --body "This looks good!"
gh issue comment 123 --body "This looks good!"
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
gh issue comment 123 --delete 456789
Show issue status summary
Show issue status summary
Status for specific repository
Status for specific repository
gh issue status --repo owner/repo
gh issue status --repo owner/repo
Pin/Unpin Issues
固定/取消固定议题
Pin issue (pinned to repo dashboard)
Pin issue (pinned to repo dashboard)
Lock conversation
Lock conversation
Lock with reason
Lock with reason
gh issue lock 123 --reason off-topic
gh issue lock 123 --reason off-topic
Transfer to another repository
Transfer to another repository
gh issue transfer 123 --repo owner/new-repo
gh issue transfer 123 --repo owner/new-repo
Confirm without prompt
Confirm without prompt
gh issue delete 123 --yes
gh issue delete 123 --yes
Develop Issue (Draft PR)
基于议题开发(草稿PR)
Create draft PR from issue
Create draft PR from issue
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
gh issue develop 123 --base main
Pull Requests (gh pr)
拉取请求 (gh pr)
Create Pull Request
创建拉取请求
Create PR interactively
Create PR interactively
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
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
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
gh pr create --labels enhancement,feature
gh pr create --labels enhancement,feature
Link to issue
Link to issue
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
List open PRs
List open PRs
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
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 --search "is:open is:pr label:review-required"
gh pr list --search "is:open is:pr label:review-required"
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]'
gh pr list --sort created --order desc
gh pr list --sort created --order desc
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 --json title,body,state,author,commits,files
gh pr view 123 --json title,body,state,author,commits,files
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)"'
gh pr view 123 --json title,state --jq '"(.title): (.state)"'
Checkout Pull Request
检出拉取请求
Checkout PR branch
Checkout PR branch
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
gh pr checkout 123 --force
Diff Pull Request
查看拉取请求差异
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
gh pr diff 123 --name-only
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
Force merge (skip checks)
Force merge (skip checks)
Close PR (as draft, not merge)
Close PR (as draft, not merge)
Close with comment
Close with comment
gh pr close 123 --comment "Closing due to..."
gh pr close 123 --comment "Closing due to..."
Reopen Pull Request
重新打开拉取请求
Reopen closed PR
Reopen closed PR
Edit interactively
Edit interactively
gh pr edit 123 --title "New title"
gh pr edit 123 --title "New title"
gh pr edit 123 --body "New description"
gh pr edit 123 --body "New description"
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
Mark draft PR as ready
Mark draft PR as ready
Pull Request Checks
拉取请求检查
View PR checks
View PR checks
Watch checks in real-time
Watch checks in real-time
Watch interval (seconds)
Watch interval (seconds)
gh pr checks 123 --watch --interval 5
gh pr checks 123 --watch --interval 5
Comment on Pull Request
评论拉取请求
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
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
gh pr comment 123 --delete 456789
Review Pull Request
审核拉取请求
Review PR (opens editor)
Review PR (opens editor)
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
gh pr review 123 --dismiss
Update PR branch with latest base branch
Update PR branch with latest base branch
gh pr update-branch 123 --force
gh pr update-branch 123 --force
Use merge strategy
Use merge strategy
gh pr update-branch 123 --merge
gh pr update-branch 123 --merge
Lock/Unlock Pull Request
锁定/解锁拉取请求
Lock PR conversation
Lock PR conversation
Lock with reason
Lock with reason
gh pr lock 123 --reason off-topic
gh pr lock 123 --reason off-topic
Revert Pull Request
还原拉取请求
Revert merged PR
Revert merged PR
Revert with specific branch name
Revert with specific branch name
gh pr revert 123 --branch revert-pr-123
gh pr revert 123 --branch revert-pr-123
Pull Request Status
拉取请求状态
Show PR status summary
Show PR status summary
Status for specific repository
Status for specific repository
gh pr status --repo owner/repo
gh pr status --repo owner/repo
GitHub Actions
GitHub Actions
Workflow Runs (gh run)
工作流运行 (gh run)
List workflow runs
List workflow runs
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 --json databaseId,status,conclusion,headBranch
gh run list --json databaseId,status,conclusion,headBranch
View run details
View run details
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
Watch with interval
Watch with interval
gh run watch 123456789 --interval 5
gh run watch 123456789 --interval 5
Rerun failed run
Rerun failed run
Rerun specific job
Rerun specific job
gh run rerun 123456789 --job 987654321
gh run rerun 123456789 --job 987654321
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
gh run download 123456789 --dir ./artifacts
Workflows (gh workflow)
工作流 (gh workflow)
List workflows
List workflows
View workflow details
View workflow details
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
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
gh workflow run ci.yml --ref develop
Action Caches (gh cache)
操作缓存 (gh cache)
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 delete 123456789
gh cache delete 123456789
Delete all caches
Delete all caches
Action Secrets (gh secret)
操作密钥 (gh secret)
Set secret (prompts for value)
Set secret (prompts for value)
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
gh secret delete MY_SECRET --env production
Action Variables (gh variable)
操作变量 (gh variable)
List variables
List variables
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
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
gh variable delete MY_VAR --env production
Projects (gh project)
项目 (gh project)
List projects
List projects
List for owner
List for owner
gh project list --owner owner
gh project list --owner owner
Open projects
Open projects
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"
gh project edit 123 --title "New Title"
gh project edit 123 --title "New Title"
Delete project
Delete project
Close project
Close 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
gh project field-list 123
gh project field-list 123
gh project field-create 123 --title "Status" --datatype single_select
gh project field-create 123 --title "Status" --datatype single_select
gh project field-delete 123 --id 456
gh project field-delete 123 --id 456
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
gh project item-edit 123 --id 456 --title "Updated title"
gh project item-edit 123 --id 456 --title "Updated title"
gh project item-delete 123 --id 456
gh project item-delete 123 --id 456
gh project item-archive 123 --id 456
gh project item-archive 123 --id 456
gh project link 123 --id 456 --link-id 789
gh project link 123 --id 456 --link-id 789
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
gh project view 123 --web
Releases (gh release)
发布 (gh release)
List releases
List releases
View latest release
View latest release
View specific release
View specific release
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
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
gh release edit v1.0.0 --notes "Updated notes"
gh release edit v1.0.0 --notes "Updated notes"
Verify release signature
Verify release signature
Verify specific asset
Verify specific asset
gh release verify-asset v1.0.0 file.tar.gz
gh release verify-asset v1.0.0 file.tar.gz
Gists (gh gist)
Gist (gh gist)
List all gists (including private)
List all gists (including private)
Limit results
Limit results
View gist files
View gist files
gh gist view abc123 --files
gh gist view abc123 --files
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
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 to directory
Clone to directory
gh gist clone abc123 my-directory
gh gist clone abc123 my-directory
Codespaces (gh codespace)
Codespaces (gh codespace)
List codespaces
List codespaces
Create codespace
Create codespace
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
SSH into codespace
SSH into codespace
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
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
Delete codespace
Delete codespace
gh codespace logs
--tail 100
gh codespace logs
--tail 100
gh codespace cp 8080:8080
gh codespace cp 8080:8080
Rebuild codespace
Rebuild codespace
Edit codespace
Edit codespace
gh codespace edit --machine standardLinux
gh codespace edit --machine standardLinux
Jupyter support
Jupyter support
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
gh codespace cp file.txt :/workspaces/file.txt
gh codespace cp :/workspaces/file.txt ./file.txt
Organizations (gh org)
组织 (gh org)
List organizations
List organizations
List for user
List for user
gh org list --user username
gh org list --user username
gh org list --json login,name,description
gh org list --json login,name,description
View organization
View organization
View organization members
View organization members
gh org view orgname --json members --jq '.members[] | .login'
gh org view orgname --json members --jq '.members[] | .login'
Search (gh search)
搜索 (gh search)
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"
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
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
gh search prs "is:open" --web
Labels (gh label)
标签 (gh 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"
gh label edit bug --name "bug-report" --color "ff0000"
gh label edit bug --name "bug-report" --color "ff0000"
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
gh label clone owner/repo --repo target/repo
SSH Keys (gh ssh-key)
SSH密钥 (gh ssh-key)
List SSH keys
List SSH keys
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
Delete by title
Delete by title
gh ssh-key delete --title "My laptop"
gh ssh-key delete --title "My laptop"
GPG Keys (gh gpg-key)
GPG密钥 (gh gpg-key)
List GPG keys
List GPG keys
gh gpg-key add ~/.ssh/id_rsa.pub
gh gpg-key add ~/.ssh/id_rsa.pub
Delete GPG key
Delete GPG key
Delete by key ID
Delete by key ID
gh gpg-key delete ABCD1234
gh gpg-key delete ABCD1234
Status (gh status)
状态 (gh status)
Show status overview
Show status overview
Status for specific repositories
Status for specific repositories
gh status --repo owner/repo
gh status --repo owner/repo
Configuration (gh config)
配置 (gh config)
List all config
List all config
Get specific value
Get specific value
Set git protocol
Set git protocol
gh config set git_protocol ssh
gh config set git_protocol ssh
Set prompt behavior
Set prompt behavior
gh config set prompt disabled
gh config set prompt enabled
gh config set prompt disabled
gh config set prompt enabled
Extensions (gh extension)
扩展 (gh extension)
List installed extensions
List installed extensions
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
Execute extension command
Execute extension command
gh extension exec my-extension --arg value
gh extension exec my-extension --arg value
Aliases (gh alias)
别名 (gh 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
Import aliases
Import aliases
gh alias import ./aliases.sh
gh alias import ./aliases.sh
API Requests (gh api)
API请求 (gh api)
Make API request
Make API request
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)
Include headers in output
Include headers in output
Silent mode (no progress output)
Silent mode (no progress output)
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
}
}
}
}'
gh api graphql
-f query='
{
viewer {
login
repositories(first: 5) {
nodes {
name
}
}
}
}'
Rulesets (gh ruleset)
规则集 (gh ruleset)
List rulesets
List rulesets
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
gh ruleset check --repo owner/repo --branch main
Attestations (gh attestation)
证明 (gh attestation)
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
gh attestation trusted-root
Completion (gh completion)
补全 (gh completion)
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
gh completion --shell=bash
gh completion --shell=zsh
Preview (gh preview)
预览 (gh preview)
List preview features
List preview features
Run preview script
Run preview script
Agent Tasks (gh agent-task)
Agent任务 (gh agent-task)
List agent tasks
List agent tasks
View agent task
View agent task
Create agent task
Create agent task
gh agent-task create --description "My task"
gh agent-task create --description "My task"
| Flag | Description |
|---|
| / | Show help for command |
| Show gh version |
| Select another repository |
| GitHub hostname |
| Filter JSON output |
| Output JSON with specified fields |
| Format JSON using Go template |
| Open in browser |
| Make additional API calls |
| Show verbose output |
| Show debug output |
| Maximum API request duration |
| Cache control (default, force, bypass) |
| Flag | 描述 |
|---|
| / | 显示命令帮助 |
| 显示gh版本 |
| 选择其他仓库 |
| GitHub主机名 |
| 过滤JSON输出 |
| 输出包含指定字段的JSON |
| 使用Go模板格式化JSON |
| 在浏览器中打开 |
| 发起额外的API请求以获取更多结果 |
| 显示详细输出 |
| 显示调试输出 |
| API请求的最长持续时间 |
| 缓存控制(默认、强制、绕过) |
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]}'
gh issue list --json number,title,labels
--jq '.[] | {number, title: .title, tags: [.labels[].name]}'
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}}
'
gh pr view 123
--template 'Title: {{.title}}
Author: {{.author.login}}
State: {{.state}}
'
Create PR from Issue
基于议题创建拉取请求
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"
gh pr create --title "Fix #123" --body "Closes #123"
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
gh pr list --search "review:required"
--json number
--jq '.[].number' |
xargs -I {} gh pr edit {} --add-label needs-review
Repository Setup Workflow
仓库设置工作流
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"
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"
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
Download artifacts on completion
Download artifacts on completion
gh run download "$RUN_ID" --dir ./artifacts
gh run download "$RUN_ID" --dir ./artifacts
Fork Sync Workflow
复刻仓库同步工作流
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
Or manual sync
Or manual sync
git fetch upstream
git checkout main
git merge upstream/main
git push origin main
git fetch upstream
git checkout main
git merge upstream/main
git push origin main
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'
alias gs='gh status'
alias gpr='gh pr view --web'
alias gir='gh issue view --web'
alias gco='gh pr checkout'
Use gh as credential helper
Use gh as credential helper
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'
git config --global credential.helper github
git config --global credential.helper github
-
Authentication: Use environment variables for automation
bash
export GH_TOKEN=$(gh auth token)
-
Default Repository: Set default to avoid repetition
bash
gh repo set-default owner/repo
-
JSON Parsing: Use jq for complex data extraction
bash
gh pr list --json number,title --jq '.[] | select(.title | contains("fix"))'
-
Pagination: Use --paginate for large result sets
bash
gh issue list --state all --paginate
-
Caching: Use cache control for frequently accessed data
bash
gh api /user --cache force
-
身份验证:自动化场景下使用环境变量
bash
export GH_TOKEN=$(gh auth token)
-
默认仓库:设置默认仓库以避免重复输入
bash
gh repo set-default owner/repo
-
JSON解析:使用jq进行复杂数据提取
bash
gh pr list --json number,title --jq '.[] | select(.title | contains("fix"))'
-
分页:对大型结果集使用--paginate参数
bash
gh issue list --state all --paginate
-
缓存:对频繁访问的数据使用缓存控制
bash
gh api /user --cache force
gh pr --help
gh issue create --help
gh pr --help
gh issue create --help
gh help formatting
gh help environment
gh help exit-codes
gh help accessibility
gh help formatting
gh help environment
gh help exit-codes
gh help accessibility