> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/zh-cn/zhi-shi-ku/042-git-integration-authentication-tokens.md).

# Git 集成身份验证令牌

**本页介绍通过 Overleaf 的** [**Git 集成**](/latex/zh-cn/zhi-shi-ku/040-git-integration.md)。这里介绍的身份验证令牌方法是 Overleaf Cloud 和 Server Pro 唯一可用的登录方式。旧的基于用户名和密码的身份验证方式已不再可用。

Overleaf Git 集成允许你将 Overleaf 项目克隆到本地仓库，并将你的 Overleaf 项目视为可向其推送和从其拉取更改的远程仓库。

摘要

要使用 Git 对 Overleaf 项目执行 Git 操作，你需要以项目所有者或协作者身份进行身份验证。你可以使用 **Git 身份验证令牌**。你可以在你的 [Overleaf 账户设置](https://www.overleaf.com/user/settings).

* 如果提示输入用户名，请输入用户名“git”
* 当提示输入密码时，请输入你的身份验证令牌
* 同一个身份验证令牌可用于通过 Git 访问你的所有项目
* 你生成的令牌应仅供你本人使用，并安全存储

执行 Git 操作时，请使用用户名 **git** ，并将身份验证令牌用作密码。同一个身份验证令牌可用于通过 Git 访问你的所有项目。你生成的令牌应仅供你本人使用，并安全存储。你可以在你的 Overleaf [账户设置](https://www.overleaf.com/user/settings) 页面的集成部分中开启和关闭 Writefull for Overleaf。

### 分步说明：如何使用 Overleaf Git 身份验证令牌克隆项目

**以下步骤说明了在使用 Git 命令行时如何克隆你的 Overleaf 项目。**

如果你使用的是其他 Git 客户端，可以使用适合该客户端的方法提供项目的 Git URL，以“git”作为用户名，并将 Git 身份验证令牌作为密码。有关 [了解 Git URL](#understanding-the-git-url) 以解释 Git URL 的各个组成部分。

1. 选择 **Git** 来自 [菜单](/latex/zh-cn/zhi-shi-ku/148-using-the-overleaf-project-menu.md) 在你的项目中。

![项目菜单 git.png](/files/0be109e0731ab0d955d5feeb0bf07d9ebb6f8c47)

1. 复制对话框中显示的 git clone 命令和 URL。创建本地仓库时你将用到它们。
2. 将该命令和 URL 粘贴到命令提示符中。请注意，提供的命令中已将“git”作为用户名。
3. 获取你的 Git 身份验证令牌
   * 如果你以前没有创建过 Git 身份验证令牌，系统会提供现在生成一个的选项。要这样做，请点击 **生成令牌**.
   * 如果你已经创建过 Git 身份验证令牌，可以使用同一个，或在你的 Overleaf [账户设置](https://www.overleaf.com/user/settings). **小贴士**：你可以 [设置 Git 凭据助手](#how-to-save-your-token-using-git-credential-helpers) 这样你就不必每次都提供令牌。
4. 当提示输入密码时，请输入你的身份验证令牌。

### 分步说明：如何将 Git 远程 URL 从基于密码的格式更新为身份验证令牌格式

**以下步骤说明如何将 Git 远程 URL 从之前基于密码的格式更新为新的基于身份验证令牌的格式。**

1\. 打开你的终端并导航到项目目录：

```
cd path/to/your/project
```

2\. 检查当前的远程 URL：

```
git remote -v
```

这将显示远程仓库的当前 URL。

3\. 使用以下命令更新远程 URL：

```
git remote set-url origin https://git@git.overleaf.com/<YOUR_PROJECT_ID>
```

将其替换为你的项目 ID

4\. 重新运行远程命令，确认更改是否成功：

```
git remote -v
```

你现在应该会看到列出的新 URL。

在下次从该本地仓库 pull 或 push 时，你需要提供一个身份验证令牌作为密码。如果你尚未生成身份验证令牌，可以在账户设置中进行生成。使用认证令牌时，如果提示输入用户名，请使用“git”，并将身份验证令牌作为密码——你可以通过使用凭据助手（见下方说明）来避免在每次操作时都提供这些凭据。

### 关于身份验证令牌的更多帮助

#### 了解 Overleaf Git 身份验证令牌

* 就像密码一样，Git 身份验证令牌也可以在执行 Git 操作时提供，以确认你的身份。就像你不会共享密码一样，你也绝不应共享你的身份验证令牌。
* 你生成的身份验证令牌可用于你通过 Git 集成访问的所有项目。
* 令牌将在一年后过期。
* **你最多可以拥有 10 个令牌。** 如果你达到了 10 个令牌的上限，应删除旧的未使用或已过期的令牌，以便创建新令牌。
* 我们建议使用 Git 凭据助手来存储你的身份验证令牌，这样你每次使用 Git 集成时就不必输入它。下面有更多关于如何设置它的信息。

#### 如何生成身份验证令牌

* 你可以在你的 [账户设置](https://www.overleaf.com/user/settings)中查看并生成 Git 身份验证令牌。你最多可以生成 10 个令牌。
* 首次使用 Git 集成时，当你选择 **Git** 在项目中 **菜单**.

#### 如何使用 Git 凭据助手保存你的令牌

我们建议使用 Git 凭据助手。这将允许你的 Git 客户端记住你的令牌。

如果你使用的是 Git 命令行客户端，可以运行此命令来存储你的凭据：

```
$ git config --global credential.helper store
```

关于此内容的更多信息，请参见此 [Git 文档页面](https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage).

#### 查看之前生成的令牌

你可以在账户设置中找到 Git 身份验证令牌列表。不过，你无法查看完整令牌。如果你记不起令牌，并且没有启用 Git 凭据助手，你需要生成一个新的。你可以在账户设置中这样做。

#### 删除已生成的令牌

令牌被删除后，在执行 Git 操作时就不能再用于验证你的身份。如果你尝试使用已过期或已删除的令牌执行操作，Git 客户端很可能会报告身份验证错误。

#### 如何与协作者协作

如果你使用 Overleaf 的 Git 集成与通常不使用 Overleaf 的人协作，你应该与他们共享项目，他们可以创建一个 Overleaf 账户。完成后，他们可以获取该项目的 Git URL，并生成自己的令牌以访问该项目。

**你绝不应共享令牌。请像对待用户名和密码一样安全地对待它。如果你觉得自己不小心共享了令牌，应将其删除。**

### 了解 Git URL

该 `git clone` 和 Git URL 可通过选择 **Git** 在项目中 **菜单**获得。或者，你可以从项目 URL 中找到 Git URL（即你在项目中时浏览器地址栏中的 URL）。

#### Overleaf Cloud

如果你的 Overleaf 项目 URL 看起来像：

```
https://www.overleaf.com/project/1234567
```

那么用于克隆项目的 Git URL 将是：

```
https://git.overleaf.com/1234567
```

你的用户名将是 **git** ，密码将是你从 Overleaf 账户获得的令牌。

项目菜单中的 Git 弹窗提供的命令和 URL 由两部分组成：(1) Git 命令行中使用的 git clone 命令，以及 (2) 完整的 Git URL，其中包含前置的“git”用户名和项目 id。

![git clone 命令和 URL 字符串的可视化说明](/files/7d3e76cf6a298dc8e4f546293d7a0df5bca6782d)

#### Overleaf Server Pro

如果你的 Overleaf 项目 URL 看起来像：

```
 https://<SHARELATEX_SITE_URL>/project/1234567
```

注意：\<SHARELATEX\_SITE\_URL> 是由你的 Overleaf Server Pro 管理员设置的主机值。

那么用于克隆项目的 Git URL 将是：

```
https://<SHARELATEX_SITE_URL>/git/1234567
```

你的用户名将是 **git** ，密码将是你从 Overleaf 账户获得的令牌。

项目菜单中的 Git 弹窗提供的命令和 URL 由两部分组成：(1) Git 命令行中使用的 git clone 命令，以及 (2) 完整的 Git URL，其中包含“git”用户名、你指定的 Overleaf 主机，以及包含项目 id 的路径。

![git clone 命令和 URL 字符串的可视化说明](/files/ca49725fb933234f87f7c5b7a95e28270608e3d0)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/zh-cn/zhi-shi-ku/042-git-integration-authentication-tokens.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
