自动同步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地址

内部gitlab地址无需事先在gitlab创建,直接输入即可,如果事先创建则会在下一步时push无法成功

删除gitlab远程仓库

#  git remote remove gitlab

查看远程remote

# git remote -v

也可以通过查看仓库下的配置文件查看

# cat .git/config
  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 @   minseo  阅读(176)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
历史上的今天:
2019-06-24 Python3之匿名函数
2019-06-24 Python3之高阶函数sorted
2018-06-24 AWK
2018-06-24 Redis+Keepalived实现高可用
2018-06-24 Redis哨兵配置
点击右上角即可分享
微信分享提示