> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squarecloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# 用 CLI 从 GitHub 部署

> 用 squarecloud app deploy 通过 GitHub App 或 webhook 把 GitHub 仓库关联到 Square Cloud 应用，并列出每次推送触发的部署。

`squarecloud app deploy` 把应用连接到 GitHub，让每次推送都会部署它。有两种方式：

* **Square Cloud GitHub App**（`app deploy github link`）：在你的仓库上安装该 App，然后关联仓库和分支。
* **Webhook**（`app deploy webhook`）：提供一个 GitHub 访问令牌，并把 CLI 打印的 URL 添加到仓库的 webhook 中。

帮助中心介绍了 GitHub 端的操作：[连接你的 GitHub 仓库](https://help.squarecloud.app/en-us/article/how-to-connect-your-github-repository-and-deploy-automatically-mr6srt/)，或设置[使用 GitHub Actions 自动部署](https://help.squarecloud.app/en-us/article/workflow-github-actions-automated-deploy-ff34mk/)。

`[appID]` 和 `--app` 是可选的：参见 [CLI 如何找到你的应用](/zh/cli-reference/quickstart#cli-如何找到你的应用)。

## `squarecloud app deploy github link`

```bash 用法 theme={"system"}
squarecloud app deploy github link <owner/repository> <branch> [--app <appID>]
```

通过 Square Cloud GitHub App 关联一个仓库和分支。该 App 必须通过你的 GitHub 账户安装在这个仓库上，且你的 GitHub 账户需要拥有该仓库的写入权限。

```bash theme={"system"}
squarecloud app deploy github link octocat/hello-world main
# 把 octocat/hello-world 的 main 分支关联到 ID= 行中的应用。
```

```bash 输出 theme={"system"}
✓ Repository octocat/hello-world (branch main) linked successfully
```

要关联其他仓库或分支，请先取消当前的关联。

## `squarecloud app deploy github unlink`

```bash 用法 theme={"system"}
squarecloud app deploy github unlink [--app <appID>]
```

从应用中移除 GitHub App 关联。

## `squarecloud app deploy webhook`

```bash 用法 theme={"system"}
squarecloud app deploy webhook <githubToken> [--app <appID>]
squarecloud app deploy webhook --remove [--app <appID>]
```

| 标志 | 说明 |
| - | - |
| `--remove` | 移除已配置的 webhook。不需要令牌。 |

用 GitHub 访问令牌（`ghp_...` 或 `github_pat_...`）创建 webhook 部署集成，并打印需要在仓库设置中添加为 webhook 的 URL。

```bash theme={"system"}
squarecloud app deploy webhook <githubToken> --app <appID>
```

```bash 输出 theme={"system"}
✓ Webhook created successfully; add it to your GitHub repository:
  <webhook URL>
```

## `squarecloud app deploy current`

```bash 用法 theme={"system"}
squarecloud app deploy current [appID] [--json]
```

显示该应用配置的 Git 集成：已关联的仓库和分支、webhook URL，或 `No Git integration configured for this application`。

```bash 输出 theme={"system"}
GitHub App: octocat/hello-world (branch main)
```

## `squarecloud app deploy list`

```bash 用法 theme={"system"}
squarecloud app deploy list [appID] [--json]
```

列出由 Git 推送触发的最近部署，每个 commit 一行，并显示每次部署的最新状态：commit 的前 8 个字符、日期、状态和分支。

```bash theme={"system"}
squarecloud app deploy list --json
# 打印原始时间线：每次部署对应一个事件数组。
```

## 相关内容

| 命令 | API | JavaScript SDK | VS Code |
| - | - | - | - |
| `github link` | [`POST .../deploy/github-app`](/zh/api-reference/endpoint/apps/deploy/github-app-link) | [`api.apps.deploys.linkGithubApp()`](/zh/sdks/js/deploys) | [关联 GitHub 仓库](/zh/vscode-extension/features#应用) |
| `github unlink` | [`DELETE .../deploy/github-app`](/zh/api-reference/endpoint/apps/deploy/github-app-unlink) | [`api.apps.deploys.unlinkGithubApp()`](/zh/sdks/js/deploys) | [取消关联 GitHub 仓库](/zh/vscode-extension/features#应用) |
| `webhook` | [`POST .../deploy/webhook`](/zh/api-reference/endpoint/apps/deploy/webhooks) | [`api.apps.deploys.setWebhook()`](/zh/sdks/js/deploys) | |
| `current` | [`GET .../deployments/current`](/zh/api-reference/endpoint/apps/deploy/info) | [`api.apps.deploys.current()`](/zh/sdks/js/deploys) | |
| `list` | [`GET .../deployments`](/zh/api-reference/endpoint/apps/deploy/list) | [`api.apps.deploys.list()`](/zh/sdks/js/deploys) | |
