Sync Two Git Repositories
Sometimes, we have a requirement which needs to sync one git repo to another location whenever there is a change in primary repo.
Sync the repo from primary to secondary
git clone --mirror https://primary_repo_url/primary.git
cd primary.git
git remote add --mirror=fetch secondary https://secondary_repo_url/secondary.git
git fetch origin
git push secondary --all
git push secondary --tags
Sync it automatically
To achieve this, we can set up a Job in Jenkins or Teamcity to monitor if any commit in primary repo, and then run script below
git fetch origin
git push secondary --all
git push secondary --tags