返回顶部
g

github-cliGitHub命令行

Comprehensive GitHub CLI (gh) reference. Covers repos, issues, PRs, Actions, releases, gists, search, projects v2, API, secrets/variables, labels, codespaces, extensions, auth, and advanced GraphQL patterns.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
7,814
下载量
免费
免费
3
收藏
概述
安装方式
版本历史

github-cli

GitHub CLI (gh) — 综合技能

版本: gh 2.66.1+
认证: gh auth login 或设置 GH_TOKEN 环境变量
不在 git 仓库目录中时,始终使用 --repo OWNER/REPO(或 -R)。



目录

  1. 1. 认证与配置
  2. 仓库
  3. 议题
  4. 拉取请求
  5. GitHub Actions(运行与工作流)
  6. 发布
  7. Gist
  8. 搜索
  9. 标签
  10. 密钥与变量
  11. 缓存
  12. Projects V2
  13. API(REST 与 GraphQL)
  14. 扩展
  15. Codespaces
  16. Copilot
  17. 其他命令
  18. JSON 输出与格式化
  19. 环境变量
  20. 高级模式
  21. 提示与注意事项

1. 认证与配置

认证

bash

交互式登录(基于浏览器的 OAuth)


gh auth login

使用来自标准输入的 PAT 登录

echo $MY_TOKEN | gh auth login --with-token

登录到 GitHub Enterprise

gh auth login --hostname enterprise.example.com

添加额外作用域(例如,Projects V2 的 project 作用域)

gh auth refresh -s project

添加 delete_repo 作用域

gh auth refresh -s delete_repo

检查认证状态(显示活动账户、作用域、令牌有效性)

gh auth status gh auth status --show-token

切换活动账户(配置了多个账户时)

gh auth switch

打印活动令牌(可用于管道传输到其他工具)

gh auth token

注销

gh auth logout

各功能所需作用域:

功能所需作用域
基本仓库/PR/议题操作repo
Gist
gist |
| 读取组织成员身份 | read:org |
| Projects V2 | project |
| 删除仓库 | delete_repo |
| Actions 工作流 | workflow |
| 读取用户资料 | user |

配置

bash

列出所有配置


gh config list

获取/设置单个值

gh config get git_protocol # https 或 ssh gh config set git_protocol ssh gh config set editor code --wait gh config set pager less -R gh config set prompt disabled # 禁用交互式提示(适合脚本) gh config set browser firefox

清除 CLI 缓存

gh config clear-cache

Git 凭据设置

bash

配置 git 使用 gh 进行 HTTPS 认证


gh auth setup-git


2. 仓库

创建

bash

交互式


gh repo create

公共仓库,克隆到本地

gh repo create my-project --public --clone

在组织中创建

gh repo create my-org/my-project --private

从本地目录创建

gh repo create my-project --private --source=. --remote=upstream --push

从模板创建

gh repo create my-project --template owner/template-repo --clone

带选项创建

gh repo create my-project --public --description 我的项目 \ --license mit --gitignore Node --add-readme

克隆

bash
gh repo clone owner/repo
gh repo clone owner/repo my-dir
gh repo clone owner/repo -- --depth=1 # 浅克隆

克隆自己的仓库(owner 默认为你)

gh repo clone my-repo

Fork

bash

Fork 当前仓库


gh repo fork

Fork 并克隆

gh repo fork owner/repo --clone

Fork 到组织

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

仅 Fork 默认分支

gh repo fork owner/repo --default-branch-only

查看

bash

查看当前仓库(README + 描述)


gh repo view
gh repo view owner/repo

在浏览器中打开

gh repo view --web

JSON 输出

gh repo view --json name,description,stargazerCount,url gh repo view --json name,stargazerCount --jq .stargazerCount

仓库的 JSON 字段: archivedAt, assignableUsers, codeOfConduct, createdAt, defaultBranchRef, deleteBranchOnMerge, description, diskUsage, forkCount, hasDiscussionsEnabled, hasIssuesEnabled, hasProjectsEnabled, hasWikiEnabled, homepageUrl, id, isArchived, isEmpty, isFork, isPrivate, isTemplate, languages, latestRelease, licenseInfo, name, nameWithOwner, owner, parent, primaryLanguage, pullRequests, pushedAt, sshUrl, stargazerCount, updatedAt, url, visibility, watchers

列出

bash

你的仓库


gh repo list
gh repo list --limit 100

其他用户/组织的仓库

gh repo list my-org

过滤

gh repo list --language go --visibility public gh repo list --topic cli --no-archived gh repo list --fork # 仅 fork gh repo list --source # 仅非 fork

JSON 输出

gh repo list --json name,stargazerCount --jq .[] | \(.name): \(.stargazerCount) stars

编辑

bash

编辑设置


gh repo edit --description 新描述
gh repo edit --homepage https://example.com
gh repo edit --enable-issues --enable-wiki
gh repo edit --enable-projects=false
gh repo edit --default-branch main
gh repo edit --enable-auto-merge
gh repo edit --delete-branch-on-merge
gh repo edit --add-topic cli,automation
gh repo edit --remove-topic old-topic
gh repo edit --template # 使其成为模板仓库

更改可见性(危险——需要确认)

gh repo edit --visibility public --accept-visibility-change-consequences

删除 / 归档

bash
gh repo delete owner/repo --yes # 需要 delete_repo 作用域
gh repo archive owner/repo --yes
gh repo unarchive owner/repo --yes

重命名

bash
gh repo rename new-name # 重命名当前仓库
gh repo rename new-name -R owner/repo

设置默认

bash

设置此本地克隆中 gh 命令使用的远程仓库


gh repo set-default owner/repo
gh repo set-default --view # 查看当前默认
gh repo set-default --unset

同步(Fork ↔ 上游)

bash

从远程父仓库同步本地仓库


gh repo sync

同步特定分支

gh repo sync --branch v1

从其父仓库同步远程 fork

gh repo sync owner/my-fork

从特定源同步

gh repo sync owner/repo --source owner2/repo2

强制同步(硬重置)

gh repo sync --force

3. 议题

创建

bash
gh issue create --title Bug 报告 --body 此处描述
gh issue create --title Bug --label bug,urgent --assignee @me
gh issue create --title 功能 --project 路线图 --milestone v2.0
gh issue create --template Bug 报告 # 使用议题模板
gh issue create --body-file description.md # 从文件读取正文
gh issue create -R owner/repo --title Bug # 不同仓库

列出

bash
gh issue list
gh issue list --state closed
gh issue list --state all --limit 100
gh issue list --label bug --assignee @me
gh issue list --author monalisa
gh issue list --milestone v2.0
gh issue list --search error no:assignee sort:created-asc

JSON 输出

gh issue list --json number,title,labels,state --jq .[] | #\(.number) \(.title)

议题的 JSON 字段: assignees, author, body, closed

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 github-cli-1776420048 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 github-cli-1776420048 技能

通过命令行安装

skillhub install github-cli-1776420048

下载

⬇ 下载 github-cli v1.0.0(免费)

文件大小: 13.9 KB | 发布时间: 2026-4-17 19:45

v1.0.0 最新 2026-4-17 19:45
Initial release: comprehensive reference for the GitHub CLI (gh).

- Covers commands for repos, issues, PRs, Actions, releases, gists, search, labels, projects v2, API, secrets, variables, codespaces, extensions, authentication, and advanced GraphQL patterns.
- Includes example usage, JSON output, required scopes, and recommended options.
- Provides installation steps for Homebrew and Apt.
- Feature-based table of contents and detailed code blocks for each command.
- Tips for automation, scripting, and environment variable support.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部