许多公司选择gitlab用作内部代码管理软件。有时候可能需要将一些开源项目同步到内部gitlab,但是只有企业版的才支持该功能。 通过git+定时任务可以简单地实现该需求:

1.将github项目clone到本地

git clone https://github.com/xxxx/xxxx.git

2.添加用于同步github项目的内部gitlab远程仓库

git remote add gitlab http://gitlab.your_company.com/xxxx/auto-pull-github.git

# 查看远程remote
git remote -v
gitlab  http://gitlab.your_company.com/xxxx/auto-pull-github.git (fetch)
gitlab  http://gitlab.your_company.com/xxxx/auto-pull-github.git (push)
origin  https://github.com/xxxx/xxxx.git (fetch)
origin  https://github.com/xxxx/xxxx.git (push)
  1. 自动同步脚本
# git-auto-sync.sh
project_path=/path/to/project

cd $project_path
git pull origin master
git push gitlab master
  1. 设置定时任务
crontab -e
# 每小时同步执行一次同步脚本
0 */1 * * * /path/to/git-auto-sync.sh

# 查看定时任务执行情况
tail -f /var/log/cron
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐