背景
- github访问很不稳定,虽然有各种方法能在网页端访问,但总不能换台服务器就要搭建VPN相关的,太麻烦
- 公司有自己的git仓库,希望能将常用的github仓库同步到私有仓库中,方便后续使用
- 笔者的场景是:需要在Dockerfile中编译opencv,使用VPN肯定不是一个好方法,各种变相的地址也只是临时的,长久之计就是将代码同步到私有仓库
实现方法(以opencv为例)
- clone原始仓库代码
git clone https://github.com/username/opencv.git cd opencv
- 添加私有仓库地址
# git remote add private <私有仓库地址> git remote add private http://user@git.tec.com/scm/tdl/opencv.git
- 查看仓库配置
git remote -v
- 将代码推到私有仓库
# 将所有分支和tag全部同步 git push --mirror private # 如果只同步所有tag git push --tags private
- 后续继续同步github上的代码
# 拉取GitHub上的最新代码 git fetch origin # 同步所有内容到私有仓库 git push --mirror private
其他
- 以上方法是手工处理,特别是后续的同步工作
- 可以使用定时脚本自动执行同步操作