Synchronize remote repositories via Git to local server and auto update it

2018-04-13 14:28:00
Memory, Renee
Original
424


My Requirements

  • Git server A: remote repositories on GitHub or something like that
  • Git server B: intranet I build

I want to build a repo on sever B which will auto synchronize with that on server A.


How to do it

My local repo is /www/git and let's say I want it to synchronize with https://github.com/easysoft/zsite and set it to do auto update at midnight.


mkdir /www/git/chanzhi .git

cd /www/git/chanzhi.git

git clone --mirror https://github.com/easysoft/zsite.git ./

Auto update


git --git-dir=/www/git/chanzhi.git remote update

Refer to this script which will make it easier.


#!/bin/bash
read -p "Enter local repor name:" name
read -p "Enter remote repo url:" url
if [ ! -n "$name" ];then
  echo "Not empty!"
else
  mkdir -p /www/git/crond_$name.git
  cd /www/git/crond_$name.git
  git clone --mirror $url ./
  echo "1 1 * * * git --git-dir=/www/git/crond_$name.git remote update" >> /var/spool/cron/root
  echo "http://git.lvtao.net/crond_$name.git"
fi

Done.

Write a Comment
Comment will be posted once reviewed.
blog-why

Why choose ZenTao

Leading

Serving 30,000+ teams

Serving 200,000+ projects

Serving 800,000+ developers

The #1 in local market share

Free & Open

Open source and unlimited to commercial

Powerful extension mechanism and various plug-ins

Available on Github

Either Self-Host or Cloud Apps

Professional

Refined ALM support

Zero downtime upgrades 

Integrate Git and SVN (pro)

Word and Excel import & export (pro)

Preview-Edit-Diff document online(ent)

Integrate OPS-Attendance-Feedback(ent)

Guaranteed

ZenTao team has involved in open source since 2004

Frequent releases and free upgrade forever(even self-hosted) 

Instant and powerful support for 20000+ companies

Easy

Out of the box, Less config

Nice price for small team($9.9)

Design to adhere Scrum Best practice

For Agile but not restrict to Agile

Flexible

Applicable for different sized teams

Applicable for Agile/Waterfall

Modules can be used in any combination

Convenient customization