将代码仓库从一个 GitLab 服务器迁移到另一个 GitLab 服务器
-mirror。
·
一、前期准备
- 创建新仓库
- 在新 GitLab 实例中创建空项目(不初始化 README)。
- 记录新仓库的 SSH/HTTPS URL(如
git@new-gitlab.com:user/repo.git
)。
- 本地环境验证
- 确保 Git 版本 ≥2.0(支持
--mirror
参数)。 - 确认本地存储空间足够容纳完整仓库。
- 确保 Git 版本 ≥2.0(支持
二、镜像克隆旧仓库
-- 克隆旧仓库的完整镜像(包含所有分支、标签和提交历史)
git clone --mirror git@old-gitlab.com:user/repo.git
-- 进入镜像目录
cd repo.git
三、配置新仓库远程地址
-- 移除旧远程地址
git remote remove origin
-- 添加新仓库地址
git remote add origin git@new-gitlab.com:user/repo.git
四、推送(二选一,绝大多数仅推送所有分支和标签)
1、仅推送所有分支和标签
# 仅迁移有效分支和标签(跳过隐藏引用)
git push origin --all # 推送所有分支
git push origin --tags # 推送所有标签
2、推送所有内容到新仓库
-- 强制推送所有分支、标签到新仓库
git push --mirror origin
题外:切换git账号密码
更多推荐
所有评论(0)