需求背景
现有需求将GitHub某开源仓库镜像到私有化部署的GitLab平台。解决项目引用开源组件时,因网络问题,直接从GitHub获取源码困难的问题。
解决方案
方法1:利用 GitLab 的 Import project 功能
前提条件:GitLab 服务器可以正常连接 GitHub
操作步骤:
打开GitLab,选择【New project】–> 【Import project】,选择【Repo by URL】,然后填写GitHub上的仓库的Clone链接。
开源公开仓库 Username和Password不需要填,私有的个人GitHub非公开仓库需要填写
方法2:手动镜像
前提条件:一个可以同时正常访问 GitHub 和私有 GitLab 平台的个人PC,并已经安装Git工具。
- 去GitLab平台创建一个空仓库,注意必须取消勾选
Initialize repository with a README
记下这个仓库地址,假设为:git@gitlab.yourcompany.com:third_party/c-periphery.git - 在本机克隆 GitHub 的 mirror,并推送到私有 GitLab
gitclone--mirrorhttps://github.com/vsergeev/c-periphery.gitcdc-periphery.gitgitpush--mirrorgit@gitlab.yourcompany.com:third_party/c-periphery.git# 这一步会把 所有分支 + tag + refs 一次性推过去。