前言
在項目變更時,常常會遷移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