需求:
需要定期把公網上的gitLab倉庫的項目備份到本地的gitLab倉庫
命令:
遠程倉庫鏡像獲取
git clone --mirror git@sourcehostname:root/financeData.git
或者
git clone --mirror http://sourcehostname/root/financeData.git
把鏡像倉庫推送到本地gitLab服務器
在本地gitLab倉庫新建好空項目:root/financeData.git
git push --mirror git@targethostname:root/financeData.git
注意:目標服務器空項目創建好之后,進行項目文件夾目錄再執行push命令。
更新遠程倉庫到本地倉庫
1)先執行遠程更新命令
git remote update
2)再執行推送命令
git push --mirror git@targethostname:root/financeData.git
注意:如果使用git@協議,需要事先把本地服務器的公鑰上傳到遠程gitLab和本地gitLab服務器上,在個人設置的添加ssh-keys菜單項添加。