自动同步github项目到本地

参考
https://blog.csdn.net/qq_41832237/article/details/103474283

开源github项目想要同步到本地gitlab

  1. 将github项目克隆至本地
    项目需要是开源的,用户有权限clone
# git clone https://github.com/liuyueming/salt.git
  1. 添加用于同步github项目的内部gitlab远程仓库
# git remote add gitlab http://gitlab.your_company.com/xxxx/auto-pull-github.git

代码尾部是内部gitlab地址
查看远程remote

# git remote -v
  1. 自动同步脚本
# cat git_auto_sync.sh 
# git-auto-sync.sh
project_path=/project_path

cd $project_path
echo "start" `date` >> /var/log/git_auto_sync.log
git pull origin main >> /var/log/git_auto_sync.log
git push gitlab main >> /var/log/git_auto_sync.log
echo "end" `date` >> /var/log/git_auto_sync.log
  1. 定时任务执行
# crontab -e
# 每小时执行一次
* */1 * * * bash git-auto-sync.sh
posted @ 2024-06-24 10:35  minseo  阅读(8)  评论(0编辑  收藏  举报