gh-cli by github/awesome-copilot
npx skills add https://github.com/github/awesome-copilot --skill gh-cliGitHub CLI (gh) 的完整参考指南 - 在命令行中无缝操作 GitHub。
版本: 2.85.0 (截至 2026 年 1 月)
# macOS
brew install gh
# 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
# Windows
winget install --id GitHub.cli
# 验证安装
gh --version
# 交互式登录 (默认: github.com)
gh auth login
# 使用特定主机名登录
gh auth login --hostname enterprise.internal
# 使用令牌登录
gh auth login --with-token < mytoken.txt
# 检查身份验证状态
gh auth status
# 切换账户
gh auth switch --hostname github.com --user username
# 登出
gh auth logout --hostname github.com --user username
# 配置 git 使用 gh 作为凭据助手
gh auth setup-git
# 查看活动令牌
gh auth token
# 刷新身份验证范围
gh auth refresh --scopes write:org,read:public_key
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
gh # 根命令
├── auth # 身份验证
│ ├── login
│ ├── logout
│ ├── refresh
│ ├── setup-git
│ ├── status
│ ├── switch
│ └── token
├── browse # 在浏览器中打开
├── 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 # 议题
│ ├── create
│ ├── list
│ ├── status
│ ├── close
│ ├── comment
│ ├── delete
│ ├── develop
│ ├── edit
│ ├── lock
│ ├── pin
│ ├── reopen
│ ├── transfer
│ ├── unlock
│ └── view
├── org # 组织
│ └── list
├── pr # 拉取请求
│ ├── create
│ ├── list
│ ├── status
│ ├── checkout
│ ├── checks
│ ├── close
│ ├── comment
│ ├── diff
│ ├── edit
│ ├── lock
│ ├── merge
│ ├── ready
│ ├── reopen
│ ├── revert
│ ├── review
│ ├── unlock
│ ├── update-branch
│ └── view
├── project # 项目
│ ├── 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 # 发布
│ ├── create
│ ├── list
│ ├── delete
│ ├── delete-asset
│ ├── download
│ ├── edit
│ ├── upload
│ ├── verify
│ ├── verify-asset
│ └── view
├── repo # 仓库
│ ├── create
│ ├── list
│ ├── archive
│ ├── autolink
│ ├── clone
│ ├── delete
│ ├── deploy-key
│ ├── edit
│ ├── fork
│ ├── gitignore
│ ├── license
│ ├── rename
│ ├── set-default
│ ├── sync
│ ├── unarchive
│ └── view
├── cache # Actions 缓存
│ ├── delete
│ └── list
├── run # 工作流运行
│ ├── cancel
│ ├── delete
│ ├── download
│ ├── list
│ ├── rerun
│ ├── view
│ └── watch
├── workflow # 工作流
│ ├── disable
│ ├── enable
│ ├── list
│ ├── run
│ └── view
├── agent-task # 代理任务
├── alias # 命令别名
│ ├── delete
│ ├── import
│ ├── list
│ └── set
├── api # API 请求
├── attestation # 制品证明
│ ├── download
│ ├── trusted-root
│ └── verify
├── completion # Shell 补全
├── config # 配置
│ ├── clear-cache
│ ├── get
│ ├── list
│ └── set
├── extension # 扩展
│ ├── browse
│ ├── create
│ ├── exec
│ ├── install
│ ├── list
│ ├── remove
│ ├── search
│ └── upgrade
├── gpg-key # GPG 密钥
│ ├── add
│ ├── delete
│ └── list
├── label # 标签
│ ├── clone
│ ├── create
│ ├── delete
│ ├── edit
│ └── list
├── preview # 预览功能
├── ruleset # 规则集
│ ├── check
│ ├── list
│ └── view
├── search # 搜索
│ ├── code
│ ├── commits
│ ├── issues
│ ├── prs
│ └── repos
├── secret # 密钥
│ ├── delete
│ ├── list
│ └── set
├── ssh-key # SSH 密钥
│ ├── add
│ ├── delete
│ └── list
├── status # 状态概览
└── variable # 变量
├── delete
├── get
├── list
└── set
# 列出所有配置
gh config list
# 获取特定配置值
gh config list git_protocol
gh config get editor
# 设置配置值
gh config set editor vim
gh config set git_protocol ssh
gh config set prompt disabled
gh config set pager "less -R"
# 清除配置缓存
gh config clear-cache
# GitHub 令牌 (用于自动化)
export GH_TOKEN=ghp_xxxxxxxxxxxx
# GitHub 主机名
export GH_HOST=github.com
# 禁用提示
export GH_PROMPT_DISABLED=true
# 自定义编辑器
export GH_EDITOR=vim
# 自定义分页器
export GH_PAGER=less
# HTTP 超时
export GH_TIMEOUT=30
# 自定义仓库 (覆盖默认值)
export GH_REPO=owner/repo
# 自定义 git 协议
export GH_ENTERPRISE_HOSTNAME=hostname
# 交互式登录
gh auth login
# 基于 Web 的身份验证
gh auth login --web
# 使用剪贴板获取 OAuth 代码
gh auth login --web --clipboard
# 使用特定 git 协议
gh auth login --git-protocol ssh
# 使用自定义主机名 (GitHub Enterprise)
gh auth login --hostname enterprise.internal
# 从 stdin 使用令牌登录
gh auth login --with-token < token.txt
# 不安全存储 (纯文本)
gh auth login --insecure-storage
# 显示所有身份验证状态
gh auth status
# 仅显示活动账户
gh auth status --active
# 显示特定主机名
gh auth status --hostname github.com
# 在输出中显示令牌
gh auth status --show-token
# JSON 输出
gh auth status --json hosts
# 使用 jq 过滤
gh auth status --json hosts --jq '.hosts | add'
# 交互式切换
gh auth switch
# 切换到特定用户/主机
gh auth switch --hostname github.com --user monalisa
# 打印身份验证令牌
gh auth token
# 特定主机/用户的令牌
gh auth token --hostname github.com --user monalisa
# 刷新凭据
gh auth refresh
# 添加范围
gh auth refresh --scopes write:org,read:public_key
# 移除范围
gh auth refresh --remove-scopes delete_repo
# 重置为默认范围
gh auth refresh --reset-scopes
# 使用剪贴板
gh auth refresh --clipboard
# 设置 git 凭据助手
gh auth setup-git
# 为特定主机设置
gh auth setup-git --hostname enterprise.internal
# 即使主机未知也强制设置
gh auth setup-git --hostname enterprise.internal --force
# 在浏览器中打开仓库
gh browse
# 打开特定路径
gh browse script/
gh browse main.go:312
# 打开议题或 PR
gh browse 123
# 打开提交
gh browse 77507cd94ccafcf568f8560cfecde965fcfa63
# 使用特定分支打开
gh browse main.go --branch bug-fix
# 打开不同的仓库
gh browse --repo owner/repo
# 打开特定页面
gh browse --actions # Actions 标签页
gh browse --projects # Projects 标签页
gh browse --releases # Releases 标签页
gh browse --settings # 设置页面
gh browse --wiki # Wiki 页面
# 打印 URL 而不是打开
gh browse --no-browser
# 创建新仓库
gh repo create my-repo
# 创建带描述的仓库
gh repo create my-repo --description "My awesome project"
# 创建公开仓库
gh repo create my-repo --public
# 创建私有仓库
gh repo create my-repo --private
# 创建带主页的仓库
gh repo create my-repo --homepage https://example.com
# 创建带许可证的仓库
gh repo create my-repo --license mit
# 创建带 .gitignore 的仓库
gh repo create my-repo --gitignore python
# 初始化为模板仓库
gh repo create my-repo --template
# 在组织中创建仓库
gh repo create org/my-repo
# 不在本地克隆的情况下创建仓库
gh repo create my-repo --source=.
# 禁用议题
gh repo create my-repo --disable-issues
# 禁用 Wiki
gh repo create my-repo --disable-wiki
# 克隆仓库
gh repo clone owner/repo
# 克隆到特定目录
gh repo clone owner/repo my-directory
# 使用不同分支克隆
gh repo clone owner/repo --branch develop
# 列出所有仓库
gh repo list
# 列出所有者的仓库
gh repo list owner
# 限制结果数量
gh repo list --limit 50
# 仅公开仓库
gh repo list --public
# 仅源仓库 (非复刻)
gh repo list --source
# JSON 输出
gh repo list --json name,visibility,owner
# 表格输出
gh repo list --limit 100 | tail -n +2
# 使用 jq 过滤
gh repo list --json name --jq '.[].name'
# 查看仓库详情
gh repo view
# 查看特定仓库
gh repo view owner/repo
# JSON 输出
gh repo view --json name,description,defaultBranchRef
# 在浏览器中查看
gh repo view --web
# 编辑描述
gh repo edit --description "New description"
# 设置主页
gh repo edit --homepage https://example.com
# 更改可见性
gh repo edit --visibility private
gh repo edit --visibility public
# 启用/禁用功能
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 --default-branch main
# 重命名仓库
gh repo rename new-name
# 归档仓库
gh repo archive
gh repo unarchive
# 删除仓库
gh repo delete owner/repo
# 无需确认提示
gh repo delete owner/repo --yes
# 复刻仓库
gh repo fork owner/repo
# 复刻到组织
gh repo fork owner/repo --org org-name
# 复刻后克隆
gh repo fork owner/repo --clone
# 复刻的远程名称
gh repo fork owner/repo --remote-name upstream
# 与上游同步复刻
gh repo sync
# 同步特定分支
gh repo sync --branch feature
# 强制同步
gh repo sync --force
# 为当前目录设置默认仓库
gh repo set-default
# 显式设置默认值
gh repo set-default owner/repo
# 取消设置默认值
gh repo set-default --unset
# 列出自动链接
gh repo autolink list
# 添加自动链接
gh repo autolink add \
--key-prefix JIRA- \
--url-template https://jira.example.com/browse/<num>
# 删除自动链接
gh repo autolink delete 12345
# 列出部署密钥
gh repo deploy-key list
# 添加部署密钥
gh repo deploy-key add ~/.ssh/id_rsa.pub \
--title "Production server" \
--read-only
# 删除部署密钥
gh repo deploy-key delete 12345
# 查看 .gitignore 模板
gh repo gitignore
# 查看许可证模板
gh repo license mit
# 带全名的许可证
gh repo license mit --fullname "John Doe"
# 交互式创建议题
gh issue create
# 带标题创建
gh issue create --title "Bug: Login not working"
# 带标题和正文创建
gh issue create \
--title "Bug: Login not working" \
--body "Steps to reproduce..."
# 从文件读取正文创建
gh issue create --body-file issue.md
# 带标签创建
gh issue create --title "Fix bug" --labels bug,high-priority
# 带负责人创建
gh issue create --title "Fix bug" --assignee user1,user2
# 在特定仓库中创建
gh issue create --repo owner/repo --title "Issue title"
# 从 Web 创建议题
gh issue create --web
# 列出所有打开的议题
gh issue list
# 列出所有议题 (包括已关闭的)
gh issue list --state all
# 列出已关闭的议题
gh issue list --state closed
# 限制结果数量
gh issue list --limit 50
# 按负责人过滤
gh issue list --assignee username
gh issue list --assignee @me
# 按标签过滤
gh issue list --labels bug,enhancement
# 按里程碑过滤
gh issue list --milestone "v1.0"
# 搜索/过滤
gh issue list --search "is:open is:issue label:bug"
# JSON 输出
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,comments --jq '.[] | [.number, .title, .comments]'
# 排序方式
gh issue list --sort created --order desc
# 查看议题
gh issue view 123
# 查看带评论
gh issue view 123 --comments
# 在浏览器中查看
gh issue view 123 --web
# JSON 输出
gh issue view 123 --json title,body,state,labels,comments
# 查看特定字段
gh issue view 123 --json title --jq '.title'
# 交互式编辑
gh issue edit 123
# 编辑标题
gh issue edit 123 --title "New title"
# 编辑正文
gh issue edit 123 --body "New description"
# 添加标签
gh issue edit 123 --add-label bug,high-priority
# 移除标签
gh issue edit 123 --remove-label stale
# 添加负责人
gh issue edit 123 --add-assignee user1,user2
# 移除负责人
gh issue edit 123 --remove-assignee user1
# 设置里程碑
gh issue edit 123 --milestone "v1.0"
# 关闭议题
gh issue close 123
# 带评论关闭
gh issue close 123 --comment "Fixed in PR #456"
# 重新打开议题
gh issue reopen 123
# 添加评论
gh issue comment 123 --body "This looks good!"
# 编辑评论
gh issue comment 123 --edit 456789 --body "Updated comment"
# 删除评论
gh issue comment 123 --delete 456789
# 显示议题状态摘要
gh issue status
# 特定仓库的状态
gh issue status --repo owner/repo
# 置顶议题 (置顶到仓库仪表板)
gh issue pin 123
# 取消置顶议题
gh issue unpin 123
# 锁定对话
gh issue lock 123
# 带原因锁定
gh issue lock 123 --reason off-topic
# 解锁
gh issue unlock 123
# 转移到另一个仓库
gh issue transfer 123 --repo owner/new-repo
# 删除议题
gh issue delete 123
# 无需确认提示
gh issue delete 123 --yes
# 从议题创建草稿 PR
gh issue develop 123
# 在特定分支创建
gh issue develop 123 --branch fix/issue-123
# 使用基础分支创建
gh issue develop 123 --base main
# 交互式创建 PR
gh pr create
# 带标题创建
gh pr create --title "Feature: Add new functionality"
# 带标题和正文创建
gh pr create \
--title "Feature: Add new functionality" \
--body "This PR adds..."
# 从模板填充正文
gh pr create --body-file .github/PULL_REQUEST_TEMPLATE.md
# 设置基础分支
gh pr create --base main
# 设置头部分支 (默认: 当前分支)
gh pr create --head feature-branch
# 创建草稿 PR
gh pr create --draft
# 添加负责人
gh pr create --assignee user1,user2
# 添加审查者
gh pr create --reviewer user1,user2
# 添加标签
gh pr create --labels enhancement,feature
# 链接到议题
gh pr create --issue 123
# 在特定仓库中创建
gh pr create --repo owner/repo
# 创建后在浏览器中打开
gh pr create --web
# 列出打开的 PR
gh pr list
# 列出所有 PR
gh pr list --state all
# 列出已合并的 PR
gh pr list --state merged
# 列出已关闭 (未合并) 的 PR
gh pr list --state closed
# 按头部分支过滤
gh pr list --head feature-branch
# 按基础分支过滤
gh pr list --base main
# 按作者过滤
gh pr list --author username
gh pr list --author @me
# 按负责人过滤
gh pr list --assignee username
# 按标签过滤
gh pr list --labels bug,enhancement
# 限制结果数量
gh pr list --limit 50
# 搜索
gh pr list --search "is:open is:pr label:review-required"
# JSON 输出
gh pr list --json number,title,state,author,headRefName
# 显示检查状态
gh pr list --json number,title,statusCheckRollup --jq '.[] | [.number, .title, .statusCheckRollup[]?.status]'
# 排序方式
gh pr list --sort created --order desc
# 查看 PR
gh pr view 123
# 查看带评论
gh pr view 123 --comments
# 在浏览器中查看
gh pr view 123 --web
# JSON 输出
gh pr view 123 --json title,body,state,author,commits,files
# 查看差异
gh pr view 123 --json files --jq '.files[].path'
# 使用 jq 查询查看
gh pr view 123 --json title,state --jq '"\(.title): \(.state)"'
# 检出 PR 分支
gh pr checkout 123
# 使用特定分支名检出
gh pr checkout 123 --branch name-123
# 强制检出
gh pr checkout 123 --force
# 查看 PR 差异
gh pr diff 123
# 带颜色查看差异
gh pr diff 123 --color always
# 输出到文件
gh pr diff 123 > pr-123.patch
# 查看特定文件的差异
gh pr diff 123 --name-only
# 合并 PR
gh pr merge 123
# 使用特定方法合并
gh pr merge 123 --merge
gh pr merge 123 --squash
gh pr merge 123 --rebase
# 合并后删除分支
gh pr merge 123 --delete-branch
# 带评论合并
gh pr merge 123 --subject "Merge PR #123" --body "Merging feature"
# 合并草稿 PR
gh pr merge 123 --admin
# 强制合并 (跳过检查)
gh pr merge 123 --admin
# 关闭 PR (作为草稿,不合并)
gh pr close 123
# 带评论关闭
gh pr close 123 --comment "Closing due to..."
# 重新打开已关闭的 PR
gh pr reopen 123
# 交互式编辑
gh pr edit 123
# 编辑标题
gh pr edit 123 --title "New title"
# 编辑正文
gh pr edit 123 --body "New description"
# 添加标签
gh pr edit 123 --add-label bug,enhancement
# 移除标签
gh pr edit 123 --remove-label stale
# 添加负责人
gh pr edit 123 --add-assignee user1,user2
# 移除负责人
gh pr edit 123 --remove-assignee user1
# 添加审查者
gh pr edit 123 --add-reviewer user1,user2
# 移除审查者
gh pr edit 123 --remove-reviewer user1
# 标记为准备审查
gh pr edit 123 --ready
# 将草稿 PR 标记为准备就绪
gh pr ready 123
# 查看 PR 检查
gh pr checks 123
# 实时监视检查
gh pr checks 123 --watch
# 监视间隔 (秒)
gh pr checks 123 --watch --interval 5
# 添加评论
gh pr comment 123 --body "Looks good!"
# 评论特定行
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 --delete 456789
# 审查 PR (打开编辑器)
gh pr review 123
# 批准 PR
gh pr review 123 --approve --body "LGTM!"
# 请求更改
gh pr review 123 --request-changes \
--body "Please fix these issues"
# 评论 PR
gh pr review 123 --comment --body "Some thoughts..."
# 驳回审查
gh pr review 123 --dismiss
# 使用最新的基础分支更新 PR 分支
gh pr update-branch 123
# 强制更新
gh pr update-branch 123 --force
# 使用合并策略
gh pr update-branch 123 --merge
# 锁定 PR 对话
gh pr lock 123
# 带原因锁定
gh pr lock 123 --reason off-topic
# 解锁
gh pr unlock 123
# 还原已合并的 PR
gh pr revert 123
# 使用特定分支名还原
gh pr revert 123 --branch revert-pr-123
# 显示 PR 状态摘要
gh pr status
# 特定仓库的状态
gh pr status --repo owner/repo
# 列出工作流运行
gh run list
# 列出特定工作流
gh run list --workflow "ci.yml"
# 列出特定分支
gh run list --branch main
# 限制结果数量
gh run list --limit 20
# JSON 输出
gh run list --json databaseId,status,conclusion,headBranch
# 查看运行详情
gh run view 123456789
# 查看带详细日志的运行
gh run view 123456789 --log
# 查看特定作业
gh run view 123456789 --job 987654321
# 在浏览器中查看
gh run view 123456789 --web
# 实时监视运行
gh run watch 123456789
# 带间隔监视
gh run watch 123456789 --interval 5
# 重新运行失败的任务
gh run rerun 123456789
# 重新运行特定作业
gh run rerun 123456789 --job 987654321
# 取消运行
gh run cancel 123456789
# 删除运行
gh run delete 123456789
# 下载运行制品
gh run download 123456789
# 下载特定制品
gh run download 123456789 --name build
# 下载到目录
gh run download 123456789 --dir ./artifacts
# 列出工作流
gh workflow list
# 查看工作流详情
gh workflow view ci.yml
# 查看工作流 YAML
gh workflow view ci.yml --yaml
# 在浏览器中查看
gh workflow view ci.yml --web
# 启用工作流
gh workflow enable ci.yml
# 禁用工作流
gh workflow disable ci.yml
# 手动运行工作流
gh workflow run ci.yml
# 带输入运行
gh workflow run ci.yml \
--raw-field \
version="1.0.0" \
environment="production"
# 从特定分支运行
gh workflow run ci.yml --ref develop
# 列出缓存
gh cache list
# 列出特定分支的缓存
gh cache list --branch main
# 带限制列出
gh cache list --limit 50
# 删除缓存
gh cache delete 123456789
# 删除所有缓存
gh cache delete --all
# 列出密钥
gh secret list
# 设置密钥 (提示输入值)
gh secret set MY_SECRET
# 从环境变量设置密钥
echo "$MY_SECRET" | gh secret set MY_SECRET
# 为特定环境设置密钥
gh secret set MY_SECRET --env production
# 为组织设置密钥
gh secret set MY_SECRET --org orgname
# 删除密钥
gh secret delete MY_SECRET
# 从环境中删除
gh secret delete MY_SECRET --env production
# 列出变量
gh variable list
# 设置变量
gh variable set MY_VAR "some-value"
# 为环境设置变量
gh variable set MY_VAR "value" --env production
# 为组织设置变量
gh variable set MY_VAR "value" --org orgname
# 获取变量值
gh variable get MY_VAR
# 删除变量
gh variable delete MY_VAR
# 从环境中删除
gh variable delete MY_VAR --env production
# 列出项目
gh project list
# 列出所有者的项目
gh project list --owner owner
# 打开的项目
gh project list --open
# 查看项目
gh project view 123
# 查看项目项
gh project view 123 --format json
# 创建项目
gh project create --title "My Project"
# 在组织中创建
gh project create --title "Project" --org orgname
# 带 README 创建
gh project create --title "Project" --readme "Description here"
# 编辑项目
gh project edit 123 --title "New Title"
# 删除项目
gh project delete 123
# 关闭项目
gh project close 123
# 复制项目
gh project copy 123 --owner target-owner --title "Copy"
# 标记为模板
gh project mark-template 123
# 列出字段
gh project field-list 123
# 创建字段
gh project field-create 123 --title "Status" --datatype single_select
# 删除字段
gh project field-delete 123 --id 456
# 列出项
gh project item-list 123
# 创建项
gh project item-create 123 --title "New item"
# 将项添加到项目
gh project item-add 123 --owner-owner --repo repo --issue 456
# 编辑项
gh project item-edit 123 --id 456 --title "Updated title"
# 删除项
gh project item-delete 123 --id 456
# 归档项
gh project item-archive 123 --id 456
# 链接项
gh project link
Comprehensive reference for GitHub CLI (gh) - work seamlessly with GitHub from the command line.
Version: 2.85.0 (current as of January 2026)
# macOS
brew install gh
# 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
# Windows
winget install --id GitHub.cli
# Verify installation
gh --version
# Interactive login (default: github.com)
gh auth login
# Login with specific hostname
gh auth login --hostname enterprise.internal
# Login with token
gh auth login --with-token < mytoken.txt
# Check authentication status
gh auth status
# Switch accounts
gh auth switch --hostname github.com --user username
# Logout
gh auth logout --hostname github.com --user username
# Configure git to use gh as credential helper
gh auth setup-git
# View active token
gh auth token
# Refresh authentication scopes
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
# List all configuration
gh config list
# Get specific configuration value
gh config list git_protocol
gh config get editor
# 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"
# Clear configuration cache
gh config clear-cache
# GitHub token (for automation)
export GH_TOKEN=ghp_xxxxxxxxxxxx
# GitHub hostname
export GH_HOST=github.com
# Disable prompts
export GH_PROMPT_DISABLED=true
# Custom editor
export GH_EDITOR=vim
# Custom pager
export GH_PAGER=less
# HTTP timeout
export GH_TIMEOUT=30
# Custom repository (override default)
export GH_REPO=owner/repo
# Custom git protocol
export GH_ENTERPRISE_HOSTNAME=hostname
# Interactive login
gh auth login
# Web-based authentication
gh auth login --web
# With clipboard for OAuth code
gh auth login --web --clipboard
# With specific git protocol
gh auth login --git-protocol ssh
# With custom hostname (GitHub Enterprise)
gh auth login --hostname enterprise.internal
# Login with token from stdin
gh auth login --with-token < token.txt
# Insecure storage (plain text)
gh auth login --insecure-storage
# Show all authentication status
gh auth status
# Show active account only
gh auth status --active
# Show specific hostname
gh auth status --hostname github.com
# Show token in output
gh auth status --show-token
# JSON output
gh auth status --json hosts
# Filter with jq
gh auth status --json hosts --jq '.hosts | add'
# Interactive switch
gh auth switch
# Switch to specific user/host
gh auth switch --hostname github.com --user monalisa
# Print authentication token
gh auth token
# Token for specific host/user
gh auth token --hostname github.com --user monalisa
# Refresh credentials
gh auth refresh
# Add scopes
gh auth refresh --scopes write:org,read:public_key
# Remove scopes
gh auth refresh --remove-scopes delete_repo
# Reset to default scopes
gh auth refresh --reset-scopes
# With clipboard
gh auth refresh --clipboard
# Setup git credential helper
gh auth setup-git
# Setup for specific host
gh auth setup-git --hostname enterprise.internal
# Force setup even if host not known
gh auth setup-git --hostname enterprise.internal --force
# Open repository in browser
gh browse
# Open specific path
gh browse script/
gh browse main.go:312
# Open issue or PR
gh browse 123
# Open commit
gh browse 77507cd94ccafcf568f8560cfecde965fcfa63
# Open with specific branch
gh browse main.go --branch bug-fix
# Open different repository
gh browse --repo owner/repo
# 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
# Print URL instead of opening
gh browse --no-browser
# Create new repository
gh repo create my-repo
# Create with description
gh repo create my-repo --description "My awesome project"
# Create public repository
gh repo create my-repo --public
# Create private repository
gh repo create my-repo --private
# Create with homepage
gh repo create my-repo --homepage https://example.com
# Create with license
gh repo create my-repo --license mit
# Create with gitignore
gh repo create my-repo --gitignore python
# Initialize as template repository
gh repo create my-repo --template
# Create repository in organization
gh repo create org/my-repo
# Create without cloning locally
gh repo create my-repo --source=.
# Disable issues
gh repo create my-repo --disable-issues
# Disable wiki
gh repo create my-repo --disable-wiki
# Clone repository
gh repo clone owner/repo
# Clone to specific directory
gh repo clone owner/repo my-directory
# Clone with different branch
gh repo clone owner/repo --branch develop
# List all repositories
gh repo list
# List repositories for owner
gh repo list owner
# Limit results
gh repo list --limit 50
# Public repositories only
gh repo list --public
# Source repositories only (not forks)
gh repo list --source
# JSON output
gh repo list --json name,visibility,owner
# Table output
gh repo list --limit 100 | tail -n +2
# Filter with jq
gh repo list --json name --jq '.[].name'
# View repository details
gh repo view
# View specific repository
gh repo view owner/repo
# JSON output
gh repo view --json name,description,defaultBranchRef
# View in browser
gh repo view --web
# Edit description
gh repo edit --description "New description"
# Set homepage
gh repo edit --homepage https://example.com
# Change visibility
gh repo edit --visibility private
gh repo edit --visibility public
# 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
# Set default branch
gh repo edit --default-branch main
# Rename repository
gh repo rename new-name
# Archive repository
gh repo archive
gh repo unarchive
# Delete repository
gh repo delete owner/repo
# Confirm without prompt
gh repo delete owner/repo --yes
# Fork repository
gh repo fork owner/repo
# Fork to organization
gh repo fork owner/repo --org org-name
# Clone after forking
gh repo fork owner/repo --clone
# Remote name for fork
gh repo fork owner/repo --remote-name upstream
# Sync fork with upstream
gh repo sync
# Sync specific branch
gh repo sync --branch feature
# Force sync
gh repo sync --force
# Set default repository for current directory
gh repo set-default
# Set default explicitly
gh repo set-default owner/repo
# Unset default
gh repo set-default --unset
# List autolinks
gh repo autolink list
# Add autolink
gh repo autolink add \
--key-prefix JIRA- \
--url-template https://jira.example.com/browse/<num>
# Delete autolink
gh repo autolink delete 12345
# List deploy keys
gh repo deploy-key list
# Add deploy key
gh repo deploy-key add ~/.ssh/id_rsa.pub \
--title "Production server" \
--read-only
# Delete deploy key
gh repo deploy-key delete 12345
# View gitignore template
gh repo gitignore
# View license template
gh repo license mit
# License with full name
gh repo license mit --fullname "John Doe"
# Create issue interactively
gh issue create
# Create with title
gh issue create --title "Bug: Login not working"
# Create with title and body
gh issue create \
--title "Bug: Login not working" \
--body "Steps to reproduce..."
# Create with body from file
gh issue create --body-file issue.md
# Create with labels
gh issue create --title "Fix bug" --labels bug,high-priority
# Create with assignees
gh issue create --title "Fix bug" --assignee user1,user2
# Create in specific repository
gh issue create --repo owner/repo --title "Issue title"
# Create issue from web
gh issue create --web
# List all open issues
gh issue list
# List all issues (including closed)
gh issue list --state all
# List closed issues
gh issue list --state closed
# Limit results
gh issue list --limit 50
# Filter by assignee
gh issue list --assignee username
gh issue list --assignee @me
# Filter by labels
gh issue list --labels bug,enhancement
# Filter by milestone
gh issue list --milestone "v1.0"
# Search/filter
gh issue list --search "is:open is:issue label:bug"
# JSON output
gh issue list --json number,title,state,author
# Table view
gh issue list --json number,title,labels --jq '.[] | [.number, .title, .labels[].name] | @tsv'
# Show comments count
gh issue list --json number,title,comments --jq '.[] | [.number, .title, .comments]'
# Sort by
gh issue list --sort created --order desc
# View issue
gh issue view 123
# View with comments
gh issue view 123 --comments
# View in browser
gh issue view 123 --web
# JSON output
gh issue view 123 --json title,body,state,labels,comments
# View specific fields
gh issue view 123 --json title --jq '.title'
# Edit interactively
gh issue edit 123
# Edit title
gh issue edit 123 --title "New title"
# Edit body
gh issue edit 123 --body "New description"
# Add labels
gh issue edit 123 --add-label bug,high-priority
# Remove labels
gh issue edit 123 --remove-label stale
# Add assignees
gh issue edit 123 --add-assignee user1,user2
# Remove assignees
gh issue edit 123 --remove-assignee user1
# Set milestone
gh issue edit 123 --milestone "v1.0"
# Close issue
gh issue close 123
# Close with comment
gh issue close 123 --comment "Fixed in PR #456"
# Reopen issue
gh issue reopen 123
# Add comment
gh issue comment 123 --body "This looks good!"
# Edit comment
gh issue comment 123 --edit 456789 --body "Updated comment"
# Delete comment
gh issue comment 123 --delete 456789
# Show issue status summary
gh issue status
# Status for specific repository
gh issue status --repo owner/repo
# Pin issue (pinned to repo dashboard)
gh issue pin 123
# Unpin issue
gh issue unpin 123
# Lock conversation
gh issue lock 123
# Lock with reason
gh issue lock 123 --reason off-topic
# Unlock
gh issue unlock 123
# Transfer to another repository
gh issue transfer 123 --repo owner/new-repo
# Delete issue
gh issue delete 123
# Confirm without prompt
gh issue delete 123 --yes
# Create draft PR from issue
gh issue develop 123
# Create in specific branch
gh issue develop 123 --branch fix/issue-123
# Create with base branch
gh issue develop 123 --base main
# Create PR interactively
gh pr create
# Create with title
gh pr create --title "Feature: Add new functionality"
# Create with title and body
gh pr create \
--title "Feature: Add new functionality" \
--body "This PR adds..."
# Fill body from template
gh pr create --body-file .github/PULL_REQUEST_TEMPLATE.md
# Set base branch
gh pr create --base main
# Set head branch (default: current branch)
gh pr create --head feature-branch
# Create draft PR
gh pr create --draft
# Add assignees
gh pr create --assignee user1,user2
# Add reviewers
gh pr create --reviewer user1,user2
# Add labels
gh pr create --labels enhancement,feature
# Link to issue
gh pr create --issue 123
# Create in specific repository
gh pr create --repo owner/repo
# Open in browser after creation
gh pr create --web
# List open PRs
gh pr list
# List all PRs
gh pr list --state all
# List merged PRs
gh pr list --state merged
# List closed (not merged) PRs
gh pr list --state closed
# Filter by head branch
gh pr list --head feature-branch
# Filter by base branch
gh pr list --base main
# Filter by author
gh pr list --author username
gh pr list --author @me
# Filter by assignee
gh pr list --assignee username
# Filter by labels
gh pr list --labels bug,enhancement
# Limit results
gh pr list --limit 50
# Search
gh pr list --search "is:open is:pr label:review-required"
# JSON output
gh pr list --json number,title,state,author,headRefName
# Show check status
gh pr list --json number,title,statusCheckRollup --jq '.[] | [.number, .title, .statusCheckRollup[]?.status]'
# Sort by
gh pr list --sort created --order desc
# View PR
gh pr view 123
# View with comments
gh pr view 123 --comments
# View in browser
gh pr view 123 --web
# JSON output
gh pr view 123 --json title,body,state,author,commits,files
# View diff
gh pr view 123 --json files --jq '.files[].path'
# View with jq query
gh pr view 123 --json title,state --jq '"\(.title): \(.state)"'
# Checkout PR branch
gh pr checkout 123
# Checkout with specific branch name
gh pr checkout 123 --branch name-123
# Force checkout
gh pr checkout 123 --force
# View PR diff
gh pr diff 123
# View diff with color
gh pr diff 123 --color always
# Output to file
gh pr diff 123 > pr-123.patch
# View diff of specific files
gh pr diff 123 --name-only
# Merge PR
gh pr merge 123
# Merge with specific method
gh pr merge 123 --merge
gh pr merge 123 --squash
gh pr merge 123 --rebase
# Delete branch after merge
gh pr merge 123 --delete-branch
# Merge with comment
gh pr merge 123 --subject "Merge PR #123" --body "Merging feature"
# Merge draft PR
gh pr merge 123 --admin
# Force merge (skip checks)
gh pr merge 123 --admin
# Close PR (as draft, not merge)
gh pr close 123
# Close with comment
gh pr close 123 --comment "Closing due to..."
# Reopen closed PR
gh pr reopen 123
# Edit interactively
gh pr edit 123
# Edit title
gh pr edit 123 --title "New title"
# Edit body
gh pr edit 123 --body "New description"
# Add labels
gh pr edit 123 --add-label bug,enhancement
# Remove labels
gh pr edit 123 --remove-label stale
# Add assignees
gh pr edit 123 --add-assignee user1,user2
# Remove assignees
gh pr edit 123 --remove-assignee user1
# Add reviewers
gh pr edit 123 --add-reviewer user1,user2
# Remove reviewers
gh pr edit 123 --remove-reviewer user1
# Mark as ready for review
gh pr edit 123 --ready
# Mark draft PR as ready
gh pr ready 123
# View PR checks
gh pr checks 123
# Watch checks in real-time
gh pr checks 123 --watch
# Watch interval (seconds)
gh pr checks 123 --watch --interval 5
# Add comment
gh pr comment 123 --body "Looks good!"
# Comment on specific line
gh pr comment 123 --body "Fix this" \
--repo owner/repo \
--head-owner owner --head-branch feature
# Edit comment
gh pr comment 123 --edit 456789 --body "Updated"
# Delete comment
gh pr comment 123 --delete 456789
# Review PR (opens editor)
gh pr review 123
# Approve PR
gh pr review 123 --approve --body "LGTM!"
# Request changes
gh pr review 123 --request-changes \
--body "Please fix these issues"
# Comment on PR
gh pr review 123 --comment --body "Some thoughts..."
# Dismiss review
gh pr review 123 --dismiss
# Update PR branch with latest base branch
gh pr update-branch 123
# Force update
gh pr update-branch 123 --force
# Use merge strategy
gh pr update-branch 123 --merge
# Lock PR conversation
gh pr lock 123
# Lock with reason
gh pr lock 123 --reason off-topic
# Unlock
gh pr unlock 123
# Revert merged PR
gh pr revert 123
# Revert with specific branch name
gh pr revert 123 --branch revert-pr-123
# Show PR status summary
gh pr status
# Status for specific repository
gh pr status --repo owner/repo
# List workflow runs
gh run list
# List for specific workflow
gh run list --workflow "ci.yml"
# List for specific branch
gh run list --branch main
# Limit results
gh run list --limit 20
# JSON output
gh run list --json databaseId,status,conclusion,headBranch
# View run details
gh run view 123456789
# View run with verbose logs
gh run view 123456789 --log
# View specific job
gh run view 123456789 --job 987654321
# View in browser
gh run view 123456789 --web
# Watch run in real-time
gh run watch 123456789
# Watch with interval
gh run watch 123456789 --interval 5
# Rerun failed run
gh run rerun 123456789
# Rerun specific job
gh run rerun 123456789 --job 987654321
# Cancel run
gh run cancel 123456789
# Delete run
gh run delete 123456789
# Download run artifacts
gh run download 123456789
# Download specific artifact
gh run download 123456789 --name build
# Download to directory
gh run download 123456789 --dir ./artifacts
# List workflows
gh workflow list
# View workflow details
gh workflow view ci.yml
# View workflow YAML
gh workflow view ci.yml --yaml
# View in browser
gh workflow view ci.yml --web
# Enable workflow
gh workflow enable ci.yml
# Disable workflow
gh workflow disable ci.yml
# Run workflow manually
gh workflow run ci.yml
# Run with inputs
gh workflow run ci.yml \
--raw-field \
version="1.0.0" \
environment="production"
# Run from specific branch
gh workflow run ci.yml --ref develop
# List caches
gh cache list
# List for specific branch
gh cache list --branch main
# List with limit
gh cache list --limit 50
# Delete cache
gh cache delete 123456789
# Delete all caches
gh cache delete --all
# List secrets
gh secret list
# Set secret (prompts for value)
gh secret set MY_SECRET
# Set secret from environment
echo "$MY_SECRET" | gh secret set MY_SECRET
# Set secret for specific environment
gh secret set MY_SECRET --env production
# Set secret for organization
gh secret set MY_SECRET --org orgname
# Delete secret
gh secret delete MY_SECRET
# Delete from environment
gh secret delete MY_SECRET --env production
# List variables
gh variable list
# Set variable
gh variable set MY_VAR "some-value"
# Set variable for environment
gh variable set MY_VAR "value" --env production
# Set variable for organization
gh variable set MY_VAR "value" --org orgname
# Get variable value
gh variable get MY_VAR
# Delete variable
gh variable delete MY_VAR
# Delete from environment
gh variable delete MY_VAR --env production
# List projects
gh project list
# List for owner
gh project list --owner owner
# Open projects
gh project list --open
# View project
gh project view 123
# View project items
gh project view 123 --format json
# Create project
gh project create --title "My Project"
# Create in organization
gh project create --title "Project" --org orgname
# Create with readme
gh project create --title "Project" --readme "Description here"
# Edit project
gh project edit 123 --title "New Title"
# Delete project
gh project delete 123
# Close project
gh project close 123
# Copy project
gh project copy 123 --owner target-owner --title "Copy"
# Mark template
gh project mark-template 123
# List fields
gh project field-list 123
# Create field
gh project field-create 123 --title "Status" --datatype single_select
# Delete field
gh project field-delete 123 --id 456
# List items
gh project item-list 123
# Create item
gh project item-create 123 --title "New item"
# Add item to project
gh project item-add 123 --owner-owner --repo repo --issue 456
# Edit item
gh project item-edit 123 --id 456 --title "Updated title"
# Delete item
gh project item-delete 123 --id 456
# Archive item
gh project item-archive 123 --id 456
# Link items
gh project link 123 --id 456 --link-id 789
# Unlink items
gh project unlink 123 --id 456 --link-id 789
# View project in browser
gh project view 123 --web
# List releases
gh release list
# View latest release
gh release view
# View specific release
gh release view v1.0.0
# View in browser
gh release view v1.0.0 --web
# Create release
gh release create v1.0.0 \
--notes "Release notes here"
# Create release with notes from file
gh release create v1.0.0 --notes-file notes.md
# Create release with target
gh release create v1.0.0 --target main
# Create release as draft
gh release create v1.0.0 --draft
# Create pre-release
gh release create v1.0.0 --prerelease
# Create release with title
gh release create v1.0.0 --title "Version 1.0.0"
# Upload asset to release
gh release upload v1.0.0 ./file.tar.gz
# Upload multiple assets
gh release upload v1.0.0 ./file1.tar.gz ./file2.tar.gz
# Upload with label (casing sensitive)
gh release upload v1.0.0 ./file.tar.gz --casing
# Delete release
gh release delete v1.0.0
# Delete with cleanup tag
gh release delete v1.0.0 --yes
# Delete specific asset
gh release delete-asset v1.0.0 file.tar.gz
# Download release assets
gh release download v1.0.0
# Download specific asset
gh release download v1.0.0 --pattern "*.tar.gz"
# Download to directory
gh release download v1.0.0 --dir ./downloads
# Download archive (zip/tar)
gh release download v1.0.0 --archive zip
# Edit release
gh release edit v1.0.0 --notes "Updated notes"
# Verify release signature
gh release verify v1.0.0
# Verify specific asset
gh release verify-asset v1.0.0 file.tar.gz
# List gists
gh gist list
# List all gists (including private)
gh gist list --public
# Limit results
gh gist list --limit 20
# View gist
gh gist view abc123
# View gist files
gh gist view abc123 --files
# Create gist
gh gist create script.py
# Create gist with description
gh gist create script.py --desc "My script"
# Create public gist
gh gist create script.py --public
# Create multi-file gist
gh gist create file1.py file2.py
# Create from stdin
echo "print('hello')" | gh gist create
# Edit gist
gh gist edit abc123
# Delete gist
gh gist delete abc123
# Rename gist file
gh gist rename abc123 --filename old.py new.py
# Clone gist
gh gist clone abc123
# Clone to directory
gh gist clone abc123 my-directory
# List codespaces
gh codespace list
# Create codespace
gh codespace create
# Create with specific repository
gh codespace create --repo owner/repo
# Create with branch
gh codespace create --branch develop
# Create with specific machine
gh codespace create --machine premiumLinux
# View codespace details
gh codespace view
# SSH into codespace
gh codespace ssh
# SSH with specific command
gh codespace ssh --command "cd /workspaces && ls"
# Open codespace in browser
gh codespace code
# Open in VS Code
gh codespace code --codec
# Open with specific path
gh codespace code --path /workspaces/repo
# Stop codespace
gh codespace stop
# Delete codespace
gh codespace delete
# View logs
gh codespace logs
--tail 100
# View ports
gh codespace ports
# Forward port
gh codespace cp 8080:8080
# Rebuild codespace
gh codespace rebuild
# Edit codespace
gh codespace edit --machine standardLinux
# Jupyter support
gh codespace jupyter
# Copy files to/from codespace
gh codespace cp file.txt :/workspaces/file.txt
gh codespace cp :/workspaces/file.txt ./file.txt
# List organizations
gh org list
# List for user
gh org list --user username
# JSON output
gh org list --json login,name,description
# View organization
gh org view orgname
# View organization members
gh org view orgname --json members --jq '.members[] | .login'
# Search code
gh search code "TODO"
# Search in specific repository
gh search code "TODO" --repo owner/repo
# Search commits
gh search commits "fix bug"
# Search issues
gh search issues "label:bug state:open"
# Search PRs
gh search prs "is:open is:pr review:required"
# Search repositories
gh search repos "stars:>1000 language:python"
# Limit results
gh search repos "topic:api" --limit 50
# JSON output
gh search repos "stars:>100" --json name,description,stargazers
# Order results
gh search repos "language:rust" --order desc --sort stars
# Search with extensions
gh search code "import" --extension py
# Web search (open in browser)
gh search prs "is:open" --web
# List labels
gh label list
# Create label
gh label create bug --color "d73a4a" --description "Something isn't working"
# Create with hex color
gh label create enhancement --color "#a2eeef"
# Edit label
gh label edit bug --name "bug-report" --color "ff0000"
# Delete label
gh label delete bug
# Clone labels from repository
gh label clone owner/repo
# Clone to specific repository
gh label clone owner/repo --repo target/repo
# List SSH keys
gh ssh-key list
# Add SSH key
gh ssh-key add ~/.ssh/id_rsa.pub --title "My laptop"
# Add key with type
gh ssh-key add ~/.ssh/id_ed25519.pub --type "authentication"
# Delete SSH key
gh ssh-key delete 12345
# Delete by title
gh ssh-key delete --title "My laptop"
# List GPG keys
gh gpg-key list
# Add GPG key
gh gpg-key add ~/.ssh/id_rsa.pub
# Delete GPG key
gh gpg-key delete 12345
# Delete by key ID
gh gpg-key delete ABCD1234
# Show status overview
gh status
# Status for specific repositories
gh status --repo owner/repo
# JSON output
gh status --json
# List all config
gh config list
# Get specific value
gh config get editor
# Set value
gh config set editor vim
# Set git protocol
gh config set git_protocol ssh
# Clear cache
gh config clear-cache
# Set prompt behavior
gh config set prompt disabled
gh config set prompt enabled
# List installed extensions
gh extension list
# Search extensions
gh extension search github
# Install extension
gh extension install owner/extension-repo
# Install from branch
gh extension install owner/extension-repo --branch develop
# Upgrade extension
gh extension upgrade extension-name
# Remove extension
gh extension remove extension-name
# Create new extension
gh extension create my-extension
# Browse extensions
gh extension browse
# Execute extension command
gh extension exec my-extension --arg value
# List aliases
gh alias list
# Set alias
gh alias set prview 'pr view --web'
# Set shell alias
gh alias set co 'pr checkout' --shell
# Delete alias
gh alias delete prview
# Import aliases
gh alias import ./aliases.sh
# Make API request
gh api /user
# Request with method
gh api --method POST /repos/owner/repo/issues \
--field title="Issue title" \
--field body="Issue body"
# Request with headers
gh api /user \
--header "Accept: application/vnd.github.v3+json"
# Request with pagination
gh api /user/repos --paginate
# Raw output (no formatting)
gh api /user --raw
# Include headers in output
gh api /user --include
# Silent mode (no progress output)
gh api /user --silent
# Input from file
gh api --input request.json
# jq query on response
gh api /user --jq '.login'
# Field from response
gh api /repos/owner/repo --jq '.stargazers_count'
# GitHub Enterprise
gh api /user --hostname enterprise.internal
# GraphQL query
gh api graphql \
-f query='
{
viewer {
login
repositories(first: 5) {
nodes {
name
}
}
}
}'
# List rulesets
gh ruleset list
# View ruleset
gh ruleset view 123
# Check ruleset
gh ruleset check --branch feature
# Check specific repository
gh ruleset check --repo owner/repo --branch main
# Download attestation
gh attestation download owner/repo \
--artifact-id 123456
# Verify attestation
gh attestation verify owner/repo
# Get trusted root
gh attestation trusted-root
# 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
# Shell-specific instructions
gh completion --shell=bash
gh completion --shell=zsh
# List preview features
gh preview
# Run preview script
gh preview prompter
# List agent tasks
gh agent-task list
# View agent task
gh agent-task view 123
# Create agent task
gh agent-task create --description "My task"
| Flag | Description |
|---|---|
--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 |
# Basic JSON
gh repo view --json name,description
# Nested fields
gh repo view --json owner,name --jq '.owner.login + "/" + .name'
# Array operations
gh pr list --json number,title --jq '.[] | select(.number > 100)'
# Complex queries
gh issue list --json number,title,labels \
--jq '.[] | {number, title: .title, tags: [.labels[].name]}'
# Custom template
gh repo view \
--template '{{.name}}: {{.description}}'
# Multiline template
gh pr view 123 \
--template 'Title: {{.title}}
Author: {{.author.login}}
State: {{.state}}
'
# Create branch from issue
gh issue develop 123 --branch feature/issue-123
# Make changes, commit, push
git add .
git commit -m "Fix issue #123"
git push
# Create PR linking to issue
gh pr create --title "Fix #123" --body "Closes #123"
# Close multiple issues
gh issue list --search "label:stale" \
--json number \
--jq '.[].number' | \
xargs -I {} gh issue close {} --comment "Closing as stale"
# Add label to multiple PRs
gh pr list --search "review:required" \
--json number \
--jq '.[].number' | \
xargs -I {} gh pr edit {} --add-label needs-review
# Create repository with initial setup
gh repo create my-project --public \
--description "My awesome project" \
--clone \
--gitignore python \
--license mit
cd my-project
# Set up branches
git checkout -b develop
git push -u origin develop
# 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"
# Run workflow and wait
RUN_ID=$(gh workflow run ci.yml --ref main --jq '.databaseId')
# Watch the run
gh run watch "$RUN_ID"
# Download artifacts on completion
gh run download "$RUN_ID" --dir ./artifacts
# Fork repository
gh repo fork original/repo --clone
cd repo
# Add upstream remote
git remote add upstream https://github.com/original/repo.git
# Sync fork
gh repo sync
# Or manual sync
git fetch upstream
git checkout main
git merge upstream/main
git push origin main
# Add to ~/.bashrc or ~/.zshrc
eval "$(gh completion -s bash)" # or zsh/fish
# Create useful aliases
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
gh auth setup-git
# Set gh as default for repo operations
git config --global credential.helper 'gh !gh auth setup-git'
# Or manually
git config --global credential.helper github
Authentication : Use environment variables for automation
export GH_TOKEN=$(gh auth token)
Default Repository : Set default to avoid repetition
gh repo set-default owner/repo
JSON Parsing : Use jq for complex data extraction
gh pr list --json number,title --jq '.[] | select(.title | contains("fix"))'
Pagination : Use --paginate for large result sets
gh issue list --state all --paginate
Caching : Use cache control for frequently accessed data
gh api /user --cache force
# General help
gh --help
# Command help
gh pr --help
gh issue create --help
# Help topics
gh help formatting
gh help environment
gh help exit-codes
gh help accessibility
Weekly Installs
14.0K
Repository
GitHub Stars
27.0K
First Seen
Jan 23, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode13.5K
codex13.3K
github-copilot13.3K
gemini-cli13.3K
kimi-cli13.1K
amp13.0K
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装
| 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) |