# 管理从 GitLab 迁移到 GitHub的访问

设置从 GitLab 迁移到 GitHub所需的访问权限。

若要将存储库从 GitLab GitHub迁移到，需要对 **源** （GitLab 上的项目）和 **目标** （组织启用 GitHub）具有足够的访问权限。 完成本文中的步骤后，你的访问权限和权限将准备好进行迁移。

## 确定谁将执行迁移

如果执行迁移的人员**不是**GitHub组织所有者，GitHub则组织所有者必须首先向他们授予迁移者角色。

* 如果你是 GitHub 组织所有者，并且打算自己执行迁移，可以继续阅读本指南。
* 如果要将迁移者角色分配给其他人，请立即执行此作。 然后，迁移工具应执行这些指南中的其余步骤。 请参阅“[授予迁移者角色](/zh/migrations/using-github-enterprise-importer/migrate-from-gitlab/grant-the-migrator-role)”。

## 在 personal access token (classic) 上创建 GitHub

接下来，您需要创建一个personal access token (classic)，GL2GH extension of the GitHub CLI将使用它与GitHub进行通信。 所需的范围 GitHubpersonal access token (classic) 取决于你的角色和要完成的任务。

> \[!NOTE]
> 只能使用 personal access token (classic)，而不能使用 fine-grained personal access token。这意味着，如果组织使用“限制GitHub Enterprise Importer访问组织”策略，则无法使用personal access tokens (classic)。 有关详细信息，请参阅“[在企业中强制实施个人访问令牌策略](/zh/enterprise-cloud@latest/admin/enforcing-policies/enforcing-policies-for-your-enterprise/enforcing-policies-for-personal-access-tokens-in-your-enterprise#restricting-access-by-personal-access-tokens)”。

| 任务                            | 组织所有者                                                                                                                                                                                                                                | 迁移者                                                                                                                                                                                                                                  |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 为存储库迁移分配迁移者角色                 | `admin:org`                                                                                                                                                                                                                          | <svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-dash" aria-label="Not applicable" role="img"><path d="M2 7.75A.75.75 0 0 1 2.75 7h10a.75.75 0 0 1 0 1.5h-10A.75.75 0 0 1 2 7.75Z"></path></svg> |
| 运行存储库迁移（目标组织）                 |                                                                                                                                                                                                                                      |                                                                                                                                                                                                                                      |
| `repo`、`workflow`、`admin:org` |                                                                                                                                                                                                                                      |                                                                                                                                                                                                                                      |
| `repo`、`workflow`、`read:org`  |                                                                                                                                                                                                                                      |                                                                                                                                                                                                                                      |
| 下载迁移日志                        |                                                                                                                                                                                                                                      |                                                                                                                                                                                                                                      |
| `repo`、`workflow`、`admin:org` |                                                                                                                                                                                                                                      |                                                                                                                                                                                                                                      |
| `repo`、`workflow`、`read:org`  |                                                                                                                                                                                                                                      |                                                                                                                                                                                                                                      |
| 回收模型                          |                                                                                                                                                                                                                                      |                                                                                                                                                                                                                                      |
| `repo`、`workflow`、`admin:org` | <svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-dash" aria-label="Not applicable" role="img"><path d="M2 7.75A.75.75 0 0 1 2.75 7h10a.75.75 0 0 1 0 1.5h-10A.75.75 0 0 1 2 7.75Z"></path></svg> |                                                                                                                                                                                                                                      |

若要了解如何创建令牌，请参阅 [管理个人访问令牌](/zh/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic)。

## personal access token在 GitLab 上创建

GitLab personal access token 必须具有和`api``read_repository`作用域。

对于自管理 GitLab 实例，令牌必须属于 **管理员**，以便导出完成并保留用户归属。

若要了解如何创建令牌，请参阅 [Personal access tokens](https://docs.gitlab.com/user/profile/personal_access_tokens/) GitLab 文档中的信息。

## 配置 IP 允许列表 GitHub

如果使用 GitHubIP 允许列表功能，则必须将 GitHub 下面的 IP 范围添加到目标组织的允许列表。 请参阅“[管理组织允许的 IP 地址](/zh/enterprise-cloud@latest/organizations/keeping-your-organization-secure/managing-security-settings-for-your-organization/managing-allowed-ip-addresses-for-your-organization)”或“[使用 IP 允许列表限制企业网络的流入流量](/zh/enterprise-cloud@latest/admin/configuring-settings/hardening-security-for-your-enterprise/restricting-network-traffic-to-your-enterprise-with-an-ip-allow-list)”。

如果目标组织已打开 **GitHub.com**，则需要允许以下 IP 地址：

* 192.30.252.0/22
* 185.199.108.0/22
* 140.82.112.0/20
* 143.55.64.0/20
* 135.234.59.224/28 （2025 年 7 月 28 日添加）
* 2a0a:a440::/29
* 2606:50c0::/32
* 20.99.172.64/28（2025 年 7 月 28 日添加）

如果目标组织处于打开 **GHE.com** 位置，则需要允许的范围取决于数据驻留区域。 可以获取与 REST API 终结点一 GitHub Enterprise Importer 起使用 `/meta` 的 IP 范围的 up-to日期列表。 响应中的 `github_enterprise_importer` 键包含用于迁移的 IP 范围列表。

## 允许迁移绕过存储库规则集

如果目标组织或企业启用了规则集，则迁移的存储库历史记录可能会违反这些规则。 要在不禁用规则集的情况下允许迁移，请将“存储库迁移”添加到每个适用规则集的绕过列表中。  此绕过仅在迁移期间适用。 完成后，将对所有新贡献强制实施规则集。

若要配置旁路，请执行以下配置：

1. 导航到每个企业或组织规则集。
2. 在“绕过列表”部分中，单击“ **添加绕过**”。
3. 选择 **存储库迁移**。

有关详细信息，请参阅 [创建组织中存储库的规则集](/zh/organizations/managing-organization-settings/creating-rulesets-for-repositories-in-your-organization) 和 [为存储库迁移设置规则集旁路](/zh/enterprise-cloud@latest/migrations/troubleshooting/setting-ruleset-bypasses-for-repository-migrations)。

## 在 GitLab 上启用导出

必须启用要迁移的 GitLab 项目才能导出。 请参阅 GitLab 文档中有关导入 [的项目导出](https://docs.gitlab.com/administration/settings/import_and_export_settings/#enable-project-export) 和 [Sidekiq 配置](https://docs.gitlab.com/administration/sidekiq/configuration_for_imports/) 。