前言
在项目变更时,常常会迁移git仓库,这个时候完整的迁移git仓库,有利于后期的维护,由于git仓库里面包含了项目的各个分支,提交历史等git
源库:gitlab@github.news.com/groups:test.com.git
目标库: gitlab@github.xx.com/newgroups:newtest.com.gitgithub
1.克隆git的版本库服务器
git clone --bare gitlab@github.news.com/groups:test.com.git
Initialized empty Git repository in /home/test/test.com.git/ remote: Counting objects: 8569, done. remote: Compressing objects: 100% (2606/2606), done. remote: Total 8569 (delta 6374), reused 7917 (delta 5793) Receiving objects: 100% (8569/8569), 83.36 MiB | 9.57 MiB/s, done. Resolving deltas: 100% (6374/6374), done.
2.去目标仓库设置,将Protect保护去掉,以下图红框部分gitlab
gitlab->group->newtest.com->点击设置->Protected branches
3.以镜像推送的方式上传代码到gitlab服务器上spa
git push --mirror gitlab@github.xx.com:newgroups/newtest.com.git
Counting objects: 8569, done. Delta compression using up to 4 threads. Compressing objects: 100% (2025/2025), done. Writing objects: 100% (8569/8569), 83.36 MiB | 28.47 MiB/s, done. Total 8569 (delta 6374), reused 8569 (delta 6374) To gitlab@github.meizu.com:private/ba.meizu.com.git + 5269023...ec9c11e master -> master (forced update) * [new branch] feature/eco -> feature/eco * [new branch] origin/feature/eco -> origin/feature/eco
1.git仓库迁移前,目标仓库须要先建立,且为空
2.须要事先将仓库的protect权限去掉,不然在git push的时候会报错code