git仓库完整迁移

skyplay0 2019-06-27

前言
在项目变动时,经常会迁移git仓库,这个时候完整的迁移git仓库,有利于后期的维护,因为git仓库里面包含了项目的各个分支,提交历史等

git仓库完整迁移

源库:[email protected]/groups:test.com.git
目标库: [email protected]/newgroups:newtest.com.git

1.克隆git的版本库

git clone --bare [email protected]/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->group->newtest.com->点击设置->Protected branches

git仓库完整迁移

3.以镜像推送的方式上传代码到gitlab服务器上

git push --mirror [email protected]: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 [email protected]: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的时候会报错

相关推荐