doc: add docs/github-cli.md

This commit is contained in:
jaywcjlove 2024-10-30 06:30:34 +08:00
parent 72b973a923
commit 345e968c4c
3 changed files with 270 additions and 7 deletions

View File

@ -159,7 +159,6 @@ Quick Reference
[Find](./docs/find.md)<!--rehype:style=background: rgb(16 185 129);--> [Find](./docs/find.md)<!--rehype:style=background: rgb(16 185 129);-->
[FFmpeg](./docs/ffmpeg.md)<!--rehype:style=background: rgb(0 193 9);&class=contributing--> [FFmpeg](./docs/ffmpeg.md)<!--rehype:style=background: rgb(0 193 9);&class=contributing-->
[Gdb](./docs/gdb.md)<!--rehype:style=background: rgb(215 89 62);--> [Gdb](./docs/gdb.md)<!--rehype:style=background: rgb(215 89 62);-->
[Git](./docs/git.md)<!--rehype:style=background: rgb(215 89 62);&class=tag&data-lang=版本控制-->
[Glances](./docs/glances.md)<!--rehype:style=background: rgb(16 185 129);--> [Glances](./docs/glances.md)<!--rehype:style=background: rgb(16 185 129);-->
[Grep](./docs/grep.md)<!--rehype:style=background: rgb(16 185 129);--> [Grep](./docs/grep.md)<!--rehype:style=background: rgb(16 185 129);-->
[Htop](./docs/htop.md)<!--rehype:style=background: rgb(16 185 129);--> [Htop](./docs/htop.md)<!--rehype:style=background: rgb(16 185 129);-->
@ -176,7 +175,6 @@ Quick Reference
[Sed](./docs/sed.md)<!--rehype:style=background: rgb(16 185 129);--> [Sed](./docs/sed.md)<!--rehype:style=background: rgb(16 185 129);-->
[Systemd](./docs/systemd.md)<!--rehype:style=background: rgb(16 185 129);--> [Systemd](./docs/systemd.md)<!--rehype:style=background: rgb(16 185 129);-->
[SSH](./docs/ssh.md)<!--rehype:style=background: rgb(99 99 99);--> [SSH](./docs/ssh.md)<!--rehype:style=background: rgb(99 99 99);-->
[Subversion (SVN)](./docs/subversion.md)<!--rehype:style=background: rgb(99 99 99);&class=tag&data-lang=版本控制-->
[Screen](./docs/screen.md)<!--rehype:style=background: rgb(99 99 99);--> [Screen](./docs/screen.md)<!--rehype:style=background: rgb(99 99 99);-->
[Sysdig](./docs/sysdig.md)<!--rehype:style=background: rgb(1 171 199);--> [Sysdig](./docs/sysdig.md)<!--rehype:style=background: rgb(1 171 199);-->
[Tmux](./docs/tmux.md)<!--rehype:style=background: rgb(99 99 99);--> [Tmux](./docs/tmux.md)<!--rehype:style=background: rgb(99 99 99);-->
@ -189,14 +187,12 @@ Quick Reference
## 工具 ## 工具
[ChatGPT](./docs/chatgpt.md)<!--rehype:style=background: rgb(74, 161, 129);&class=tag&data-lang=AI--> [ChatGPT](./docs/chatgpt.md)<!--rehype:style=background: rgb(74, 161, 129);&class=tag&data-lang=AI-->
[Github Copilot](./docs/github-copilot.md)<!--rehype:style=background: rgb(125 45 220);&class=tag contributing&data-lang=AI&data-info=👆看看还缺点儿什么?-->
[Emacs](./docs/emacs.md)<!--rehype:style=background: rgb(98 36 134);--> [Emacs](./docs/emacs.md)<!--rehype:style=background: rgb(98 36 134);-->
[Github](./docs/github.md)<!--rehype:style=background: rgb(36 41 47);-->
[Linux Command](./docs/linux-command.md)<!--rehype:style=background: rgb(215 89 62);&class=tag&data-lang=命令速查--> [Linux Command](./docs/linux-command.md)<!--rehype:style=background: rgb(215 89 62);&class=tag&data-lang=命令速查-->
[Mitmproxy](./docs/mitmproxy.md)<!--rehype:style=background: rgb(4 92 135);--> [Mitmproxy](./docs/mitmproxy.md)<!--rehype:style=background: rgb(4 92 135);-->
[nginx](./docs/nginx.md)<!--rehype:style=background: rgb(0 153 0);--> [nginx](./docs/nginx.md)<!--rehype:style=background: rgb(0 153 0);-->
[RegEx 正则表达式](./docs/regex.md)<!--rehype:style=background: rgb(149 36 155);--> [RegEx 正则表达式](./docs/regex.md)<!--rehype:style=background: rgb(149 36 155);-->
[Semver](./docs/semver.md)<!--rehype:style=background: rgb(106 111 141);--> [Semver 语义化版本](./docs/semver.md)<!--rehype:style=background: rgb(106 111 141);-->
[Vim](./docs/vim.md)<!--rehype:style=background: rgb(9 150 8);--> [Vim](./docs/vim.md)<!--rehype:style=background: rgb(9 150 8);-->
[XPath](./docs/xpath.md)<!--rehype:style=background: rgb(91 163 230);--> [XPath](./docs/xpath.md)<!--rehype:style=background: rgb(91 163 230);-->
<!--rehype:class=home-card--> <!--rehype:class=home-card-->
@ -214,6 +210,17 @@ Quick Reference
[SDKMAN](./docs/sdkman.md)<!--rehype:style=background: rgb(0 118 198);--> [SDKMAN](./docs/sdkman.md)<!--rehype:style=background: rgb(0 118 198);-->
<!--rehype:class=home-card--> <!--rehype:class=home-card-->
## Git 版本控制
[Git](./docs/git.md)<!--rehype:style=background: rgb(215 89 62);&class=tag&data-lang=版本控制-->
[Github](./docs/github.md)<!--rehype:style=background: rgb(36 41 47);-->
[Github Copilot](./docs/github-copilot.md)<!--rehype:style=background: rgb(125 45 220);&class=tag contributing&data-lang=AI&data-info=👆看看还缺点儿什么?-->
[Github CLI](./docs/github-cli.md)<!--rehype:style=background: rgb(36 41 47);-->
[Github Actions](./docs/github-actions.md)<!--rehype:style=background: rgb(121 184 255);-->
[Gitlab CI/CD](./docs/gitlab-ci.md)<!--rehype:style=background: rgb(226 67 41);&class=contributing-->
[Subversion (SVN)](./docs/subversion.md)<!--rehype:style=background: rgb(99 99 99);&class=tag&data-lang=版本控制-->
<!--rehype:class=home-card-->
## 数据库 ## 数据库
[MySQL](./docs/mysql.md)<!--rehype:style=background: rgb(1 117 143);&class=tag&data-lang=SQL--> [MySQL](./docs/mysql.md)<!--rehype:style=background: rgb(1 117 143);&class=tag&data-lang=SQL-->
@ -256,8 +263,6 @@ Quick Reference
[Aspect Ratio](./docs/aspect-ratio.md)<!--rehype:style=background: rgb(16 185 129);--> [Aspect Ratio](./docs/aspect-ratio.md)<!--rehype:style=background: rgb(16 185 129);-->
[ASCII Code](./docs/ascii-code.md)<!--rehype:style=background: rgb(16 185 129);--> [ASCII Code](./docs/ascii-code.md)<!--rehype:style=background: rgb(16 185 129);-->
[Symbol Code](./docs/symbol-code.md)<!--rehype:style=background: rgb(16 185 129);--> [Symbol Code](./docs/symbol-code.md)<!--rehype:style=background: rgb(16 185 129);-->
[Github Actions](./docs/github-actions.md)<!--rehype:style=background: rgb(121 184 255);-->
[Gitlab CI/CD](./docs/gitlab-ci.md)<!--rehype:style=background: rgb(226 67 41);&class=contributing-->
[Colors Named](./docs/colors-named.md)<!--rehype:style=background: rgb(16 185 129);&class=tag&data-lang=CSS--> [Colors Named](./docs/colors-named.md)<!--rehype:style=background: rgb(16 185 129);&class=tag&data-lang=CSS-->
[HTTP 状态码](./docs/http-status-code.md)<!--rehype:style=background: rgb(16 185 129);--> [HTTP 状态码](./docs/http-status-code.md)<!--rehype:style=background: rgb(16 185 129);-->
[HTML 字符实体](./docs/html-char.md)<!--rehype:style=background: rgb(16 185 129);&class=tag&data-lang=HTML--> [HTML 字符实体](./docs/html-char.md)<!--rehype:style=background: rgb(16 185 129);&class=tag&data-lang=HTML-->

3
assets/github-cli.svg Normal file
View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 1984 2048" height="1em" width="1em">
<path d="M663.6 1589.6c0 8-9.2 14.4-20.8 14.4-13.2 1.2-22.4-5.2-22.4-14.4 0-8 9.2-14.4 20.8-14.4 12-1.2 22.4 5.2 22.4 14.4zm-124.4-18c-2.8 8 5.2 17.2 17.2 19.6 10.4 4 22.4 0 24.8-8s-5.2-17.2-17.2-20.8c-10.4-2.8-22 1.2-24.8 9.2zm176.8-6.8c-11.6 2.8-19.6 10.4-18.4 19.6 1.2 8 11.6 13.2 23.6 10.4 11.6-2.8 19.6-10.4 18.4-18.4-1.2-7.6-12-12.8-23.6-11.6zM979.2 32C424.4 32 0 453.2 0 1008c0 443.6 279.2 823.2 678 956.8 51.2 9.2 69.2-22.4 69.2-48.4 0-24.8-1.2-161.6-1.2-245.6 0 0-280 60-338.8-119.2 0 0-45.6-116.4-111.2-146.4 0 0-91.6-62.8 6.4-61.6 0 0 99.6 8 154.4 103.2 87.6 154.4 234.4 110 291.6 83.6 9.2-64 35.2-108.4 64-134.8-223.6-24.8-449.2-57.2-449.2-442 0-110 30.4-165.2 94.4-235.6-10.4-26-44.4-133.2 10.4-271.6 83.6-26 276 108 276 108 80-22.4 166-34 251.2-34s171.2 11.6 251.2 34c0 0 192.4-134.4 276-108 54.8 138.8 20.8 245.6 10.4 271.6 64 70.8 103.2 126 103.2 235.6 0 386-235.6 416.8-459.2 442 36.8 31.6 68 91.6 68 185.6 0 134.8-1.2 301.6-1.2 334.4 0 26 18.4 57.6 69.2 48.4 400-132.8 671.2-512.4 671.2-956 0-554.8-450-976-1004.8-976zM388.8 1411.6c-5.2 4-4 13.2 2.8 20.8 6.4 6.4 15.6 9.2 20.8 4 5.2-4 4-13.2-2.8-20.8-6.4-6.4-15.6-9.2-20.8-4zm-43.2-32.4c-2.8 5.2 1.2 11.6 9.2 15.6 6.4 4 14.4 2.8 17.2-2.8 2.8-5.2-1.2-11.6-9.2-15.6-8-2.4-14.4-1.2-17.2 2.8zm129.6 142.4c-6.4 5.2-4 17.2 5.2 24.8 9.2 9.2 20.8 10.4 26 4 5.2-5.2 2.8-17.2-5.2-24.8-8.8-9.2-20.8-10.4-26-4zm-45.6-58.8c-6.4 4-6.4 14.4 0 23.6 6.4 9.2 17.2 13.2 22.4 9.2 6.4-5.2 6.4-15.6 0-24.8-5.6-9.2-16-13.2-22.4-8z"/>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

255
docs/github-cli.md Normal file
View File

@ -0,0 +1,255 @@
Github CLI
===
GitHub CLI 的快速参考,这是一个开源命令行工具,可在终端上启用 GitHub 功能。
入门
---
### 安装
<!--rehype:wrap-class=col-span-2-->
#### Windows
<!--rehype:style=text-align: left;-->
| 工具 | 安装 | 升级 |
| :----- | :--------------------------- | :--------------------------- |
| WinGet | `winget install --id Github.cli` | `winget upgrade --id GitHub.cli` |
| Scoop | `scoop install gh` | `scoop update gh` |
| Choco | `choco install gh` | `choco upgrade gh` |
<!--rehype:className=show-header left-align-->
#### Mac OS
<!--rehype:style=text-align: left;-->
| 工具 | 安装 | 升级 |
| :------- | :-------------------- | :------------------------------------------ |
| Brew | `brew install gh` | `brew upgrade gh` |
| MacPorts | `sudo port install gh`| `sudo port selfupdate && sudo port upgrade gh` |
<!--rehype:className=show-header left-align-->
#### Linux
<!--rehype:style=text-align: left;-->
请参见 [安装说明](https://github.com/cli/cli/blob/trunk/docs/install_linux.md) 以获取其他 Linux 发行版的信息。安装脚本:
```bash
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /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 -y
```
### 基本用法
#### 帮助和文档
<!--rehype:style=text-align: left;-->
显示命令选项:
| 命令 | 描述 |
| :-------------------- | :------------------------------------------------------------------------------------------------------------- |
| `gh help [command]` | 帮助提供应用程序中任何命令的帮助。只需键入 `gh help [命令路径]` 以获取完整详细信息。 |
<!--rehype:className=style-list-arrow-->
#### 认证
<!--rehype:style=text-align: left;-->
| 命令 | 描述 |
| :-------------------- | :-------------------------------------------------------- |
| `gh auth login` | 默认通过基于网页的浏览器进行身份验证 |
| `gh auth logout` | 移除主机的身份验证配置 |
| `gh auth refresh` | 扩展或修复存储凭据的权限范围 |
| `gh auth setup-git` | 配置 Git 使用 GitHub CLI 作为凭据助手 |
| `gh auth status` | 验证并显示有关您身份验证状态的信息 |
| `gh auth token` | 打印 `gh` 配置使用的身份验证令牌 |
<!--rehype:className=style-list-arrow-->
使用 GitHub 令牌:
```shell
$ gh auth --with-token < token.txt
```
### 仓库管理
<!--rehype:wrap-class=col-span-2-->
#### 常规
<!--rehype:style=text-align: left;-->
| 命令 | 描述 |
| :------------------------ | :------------------------------------------ |
| `gh repo create` | 创建一个新的 GitHub 仓库 |
| `gh repo list [target]` | 列出某个用户或组织拥有的仓库 |
<!--rehype:className=code-nowrap left-align-->
#### 目标
<!--rehype:style=text-align: left;-->
| 命令 | 描述 |
| :--------------------------- | :-------------------------------------------------------- |
| `gh repo archive [repo]` | 存档一个 GitHub 仓库 |
| `gh repo clone [dir]` | 在本地克隆一个 GitHub 仓库 |
| `gh repo delete [repo]` | 删除一个 GitHub 仓库 |
| `gh repo deploy-key` | 管理仓库中的部署密钥 |
| `gh repo edit [repo]` | 编辑仓库设置 |
| `gh repo fork [repo]` | 创建一个仓库的分叉 |
| `gh repo rename [name]` | 重命名一个 GitHub 仓库 |
| `gh repo set-default [repo]` | 设置默认的远程仓库 |
| `gh repo sync [dest-repo]` | 从源仓库同步到目标仓库 |
| `gh repo view [repo]` | 显示一个 GitHub 仓库的描述和 README |
<!--rehype:className=code-nowrap left-align-->
### 问题
#### 搜索问题
<!--rehype:style=text-align: left;-->
| 命令 | 描述 |
| :------------------------- | :------------------------------- |
| `gh search issues [query]` | 在 GitHub 上搜索问题 |
#### 示例
<!--rehype:style=text-align: left;-->
搜索匹配关键词 "readme" 和 "typo" 的问题
```shell
$ gh search issues readme typo
```
搜索匹配短语 "broken feature" 的问题
```shell
$ gh search issues "broken feature"
```
搜索 cli 组织中的问题和拉取请求
```shell
$ gh search issues --include-prs --owner=cli
```
搜索分配给自己的开放问题
```shell
$ gh search issues --assignee=@me --state=open
```
搜索评论数超过 100 的问题
```shell
$ gh search issues --comments=">100"
```
搜索没有标签 "bug" 的问题
```shell
$ gh search issues -- -label:bug
```
### 拉取请求
**拉取请求操作**
| 命令 | 描述 |
| :---------------- | :----------------------------------------- |
| `gh pr create` | 在 GitHub 上创建拉取请求 |
| `gh pr list` | 列出 GitHub 仓库中的拉取请求 |
| `gh pr status` | 显示相关拉取请求的状态 |
**示例**
```shell
$ gh pr status
```
示例输出:
```
Current branch
#12 Remove the test feature [user:patch-2]
- All checks failing - Review required
Created by you
You have no open pull requests
Requesting a code review from you
#13 Fix tests [branch]
- 3/4 checks failing - Review required
#15 New feature [branch]
- Checks passing - Approved
```
### GitHub Actions
<!--rehype:wrap-class=col-span-2-->
**常规操作**
| 命令 | 描述 |
| :----------------------- | :--------------------------------------------------------------------------- |
| `gh workflow disable` | 禁用工作流,防止其运行或在列出工作流时显示 |
| `gh workflow enable` | 启用工作流,允许其运行并在列出工作流时显示 |
| `gh workflow list` | 列出工作流文件,默认隐藏禁用的工作流 |
| `gh workflow run` | 为给定的工作流创建一个 `workflow_dispatch` 事件 |
| `gh workflow view` | 查看工作流的摘要 |
**运行操作**
| 命令 | 描述 |
| :----------------------- | :----------------------------------------------------------- |
| `gh run cancel` | 取消一个工作流运行 |
| `gh run delete` | 删除一个工作流运行 |
| `gh run download` | 下载由 GitHub Actions 工作流运行生成的工件 |
| `gh run list` | 列出最近的工作流运行 |
| `gh run rerun` | 重新运行整个运行、仅失败的作业或运行中的特定作业 |
| `gh run view` | 查看工作流运行的摘要 |
| `gh run watch` | 观看一个运行直到其完成,显示其进度 |
### 别名
**常规别名设置**
| 命令 | 描述 |
| :----------------------- | :--------------------------------------------------------- |
| `gh alias delete` | 删除设置的别名 |
| `gh alias import` | 从 YAML 文件的内容中导入别名 |
| `gh alias list` | 打印出所有已配置的别名 |
| `gh alias set` | 定义一个单词,当调用时会展开为完整的 `gh` 命令 |
<!--rehype:className=style-list-->
### 发布
**常规操作**
| 命令 | 描述 |
| :----------------------- | :----------------------------------------- |
| `gh release create` | 为一个仓库创建新的 GitHub 发布 |
| `gh release list` | 列出一个仓库中的发布 |
<!--rehype:className=code-nowrap-->
**目标命令**
| 命令 | 描述 |
| :------------------------ | :-------------------------------------- |
| `gh release delete` | 删除一个发布 |
| `gh release delete-asset` | 从一个发布中删除一个资产 |
| `gh release download` | 从 GitHub 发布中下载资产 |
| `gh release edit` | 编辑一个发布 |
| `gh release upload` | 上传资产文件到一个 GitHub 发布 |
| `gh release view` | 查看有关一个 GitHub 发布的信息 |
<!--rehype:className=code-nowrap-->
### 配置
**目标设置**
| 命令 | 描述 |
| :------------------------ | :--------------------------------------------- |
| `gh config clear-cache` | 清除 CLI 缓存 |
| `gh config get` | 打印给定配置键的值 |
| `gh config list` | 打印配置键及其值的列表 |
| `gh config set` | 用给定键的值更新配置 |
<!--rehype:className=style-list-->