场景

在公司初创阶段,因为要跟外部合作公司共同开发项目,所以使用 github 做代码存储
后来公司内部部署了私有的代码存储库 gitlab,打算把 github 的代码迁移到内网 gitlab


准备工作

一台 Centos7 服务器,用来做临时存储和中转,当然,其他系统版本也行
安装 git,用来拉取代码,提交代码


直入主题

同步

先把 githubgitlab 同步一次

# 项目 trueCNY
# 进入对应目录并拉取代码
cd /data/ && git clone git@github.com:chainedfinance/trueCNY.git
# 进入项目目录并拉取所有分支
# 注意这里用到了 ||,是为了就算没有其他分支更新也能进入到下一步
cd trueCNY && git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done || git fetch --all && git pull --all
# 增加内网 gitlab 上同项目的地址(可以预先创建好)
git remote add gitlab git@gitlab.chainedfinance.com:github/trueCNY.git
# 提交所有分支代码到 gitlab 上并删除存储库列表里的 gitlab 存储库
git push --all gitlab && git remote rm gitlab

# 项目 eventeum
# 同上不解释
cd /data/ && git clone git@github.com:chainedfinance/eventeum.git && cd eventeum && git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done || git fetch --all && git pull --all && git remote add gitlab git@gitlab.chainedfinance.com:github/eventeum.git && git push --all gitlab && git remote rm gitlab
 
# 项目 token-factory-erc20-demo
# 同上不解释
cd /data/ && git clone git@github.com:chainedfinance/token-factory-erc20-demo.git && cd token-factory-erc20-demo && git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done || git fetch --all && git pull --all && git remote add gitlab git@gitlab.chainedfinance.com:github/token-factory-erc20-demo.git && git push --all gitlab && git remote rm gitlab

# 以下省略

更新

因为 github 依然在用,所以还需要经常把 github 的代码更新到 gitlab

# 项目 trueCNY
# 进入项目目录,更新所有分支代码,注意这里用到了 ||,是为了就算没有其他分支更新也能进入到下一步
cd /data/trueCNY && git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done || git fetch --all && git pull --all
# 增加内网 gitlab 上同项目的地址并 push 所有分支代码,最后删除这个地址
git remote add gitlab git@gitlab.chainedfinance.com:github/trueCNY.git && git push --all gitlab && git remote rm gitlab

# 项目 eventeum
# 同上不解释
cd /data/eventeum && git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done || git fetch --all && git pull --all && git remote add gitlab git@gitlab.chainedfinance.com:github/eventeum.git && git push --all gitlab && git remote rm gitlab
 
# 项目 token-factory-erc20-demo
# 同上不解释
cd /data/token-factory-erc20-demo && git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done || git fetch --all && git pull --all && git remote add gitlab git@gitlab.chainedfinance.com:github/token-factory-erc20-demo.git && git push --all gitlab && git remote rm gitlab

搞掂!


文章作者: Runfa Li
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Linux 小白鼠
网络 Linux Linux Centos7 github sync 代码同步 gitlab
觉得文章不错,打赏一点吧,1分也是爱~
打赏
微信 微信
支付宝 支付宝