Help us learn about your current experience with the documentation. Take the survey.
通过 URL 从仓库导入项目
- Tier: Free, Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
您可以通过提供 Git URL 来导入现有仓库。通过这种方式无法导入 GitLab 的 issues 和 merge requests,其他方法提供更完整的导入功能。
如果仓库太大,导入可能会超时。
您可以通过以下方式导入 Git 仓库:
先决条件
- 必须启用 通过 URL 的仓库导入源。如果未启用,请您的 GitLab 管理员启用它。在 GitLab.com 上默认启用通过 URL 的仓库导入源。
- 在目标组上至少需要 Maintainer 角色。
- 如果导入私有仓库,可能需要访问令牌(access token)而不是密码来进行身份验证访问源仓库。
使用界面导入项目
- 在左侧边栏顶部,选择 Create new( )和 New project/repository。
- 选择 Import project。
- 选择 Repository by URL。
- 输入 Git repository URL。
- 完成其余字段。从私有仓库导入需要用户名和密码(或访问令牌)。
- 选择 Create project。
您的新创建的项目将显示出来。
导入超时的项目
大型仓库的导入在三小时后可能会超时。 要导入超时的项目:
-
克隆仓库。
git clone --mirror https://example.com/group/project.git--mirror选项确保所有分支、标签和引用都被复制。 -
添加新的远程仓库。
cd repository.git git remote add new-origin https://gitlab.com/group/project.git -
将所有内容推送到新的远程仓库。
git push --mirror new-origin
使用 API 导入项目
您可以使用 Projects API 来导入 Git 仓库:
curl --location "https://gitlab.example.com/api/v4/projects/" \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <your-token>' \
--data-raw '{
"description": "New project description",
"path": "new_project_path",
"import_url": "https://username:[email protected]/group/project.git"
}'某些提供商不允许使用密码,而是要求使用访问令牌。