咱们在使用Git对项目进行管理时,有时候会遇到仓库迁移的需求,如从github迁移到本身搭建的私有Gitlab仓库。迁移步骤以下:git
举例:github
源库地址:git@github.xxx.com/groups:test.com.gitgitlab
目标库地址:gitlab@gitlab.xxx.com/newgroups:newtest.com.gitspa
在Shell执行以下命令:code
git clone --bare git@github.xxx.com/groups:test.com.git
复制代码
命令执行结果以下:cdn
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.
复制代码
一、将目标仓库master分支置为空,删除已经存在的文件(若是没有master,需先生成master分支,如添加README.md文件便可)blog
二、将master分支修改为UnProtected状态,也就是未保护状态。这个须要Git帐号具备相应权限。修改位置项目->Settings->Repository->Protected Branchesrem
进入克隆好的xxx.git文件夹中
,执行命令:it
git push --mirror gitlab@gitlab.xx.com:newgroups/newtest.com.git
复制代码
命令执行结果以下:io
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
复制代码
如上所示,完整的Git仓库就迁移归来了,包括记录和各个分支。