Automatic Sync 2 Remote Git Repositories
A simple script for synching 2 remote Git repositories
I’ve searched the web for a simple script that will sync. 2 remote repositories but I couldn’t find such script even that many seems to look for it! So I’ve created 2 simple test repositories and started testing and building such script.
What such script should do?
Well, in general, the steps for doing it are simple:
- Clone the first repository
- Add the second one as an additional remote repository
- fetch all there is in the second repository
- push the updated local repository onto the 2 remote repositories.
The remained issue is - what are the correct switches for all the above git commands?
So here it is…
#!/bin/bash # REPO_NAME=<repo>.git # ORIGIN_URL=git@<host>:<project>/$REPO_NAME # REPO1_URL=git@<host>:<project>/$REPO_NAME rm -rf $REPO_NAME git clone --bare $ORIGIN_URL cd $REPO_NAME git remote add --mirror=fetch repo1 $REPO1_URL git fetch origin --tags git fetch repo1 --tags git push origin --all git push origin --tags git push repo1 --all git push repo1 --tags
NOTE - this script is not solving cases of conflicts between the repository content!
Enjoy (and don’t forget to feedback!),
We will contact you as soon as possible.