git制作镜像库

2,485 阅读1分钟

1、镜像一个三方库

Github的访问有时候会很慢。这种情况下针对一些常用的在Github上的开源的第三方项目,有必要在本地保存一份镜像,方便内网的用户抓取。 Github duplicating-a-repository教程

xxxlib为例,首先创建一个本地的clone

git clone --mirror https://github.com/xxxlib.git

然后设定镜像仓库的地址

cd xxxlib.git
git remote set-url --push origin <your-mirror-location>

这样今后更新镜像只需要执行

git fetch -p origin
git push --mirror

也可以自己写一个crontab定时命令,定时同步源库和镜像库

2、镜像一个三方库的某个分支

有时候公司想使用某个三方库,但是要在三方库里面添加一些自己想要的特性,这样的话仅仅做一个镜像库不是很方便,每次同步之后,自己添加的代码就没了。因此能不能仅仅镜像三方库的某个分支,然后在自己的分支上添加新特性? 答案是可以的。

创建自己的库:your_repo_url

clone 你想要的分支

git clone --single-branch --branch branch_name github_repo_url

设置remote

git remote add mirrorLib your_repo_url

push指定分支到自己的库

git push -u mirrorLib
git push --tags -u mirrorLib //推送tags