How to sync a git repo to a mirrored repo

Richardicy picture Richardicy · Jan 2, 2018 · Viewed 8.6k times · Source

I want to mirror a git repo to my local repo, and wish to timely sync them, I did like this:

git clone --mirror source_url source_repo
cd source_repo
git push --mirror local_url

Now I have mirrored the source repo to my local repo, I could clone my local repo like this:

git clone local_url local_repo

But since the source repo is going update, how could I keep them sync?

Answer

Ishan Thilina Somasiri picture Ishan Thilina Somasiri · Jan 2, 2018

There are several approaches here. You can select one that is convenient to you.

  1. The approaches discussed in https://softwareengineering.stackexchange.com/questions/195456/keeping-git-repositories-on-different-hosts-in-sync (writing scripts, etc)
  2. Add a custom hook to your git repo - https://www.digitalocean.com/community/tutorials/how-to-use-git-hooks-to-automate-development-and-deployment-tasks
  3. If you are using a 3rd party tool like BitBucket, they should have built in solutions or plugins for this. Ex : https://marketplace.atlassian.com/plugins/com.englishtown.stash-hook-mirror/server/overview