I have three remote repository sitting on different remote servers.
Server A, Server B and Server C
I want to push my work to Server A, and also use the post-receive hook on server A to automatically execute a GIT pull from Server B and C to updated their repository as well at the same time.
If I read your question correctly, the only purpose of
Server BandServer Cis to backupServer A, right?In that case, you don’t have to tell
Server BandServer CtopullfromA, instead push fromAtoBandC. So the content of your post-receive hook would beassuming that
server_bandserver_care known remotes onA. See the docs ofgit pushfor a description of the--mirrorflag.If you want
BandCto become the active part, set up a cron job togit fetch Aperiodically.Another approach is to define a remote in your local repo that has three URLs:
Now, when you usually push your work to
Ausinggit push, simply do ato push all your local on
A,BandCat the same time.Another question is: why do you push to
BandCat all? It seems as you are doing it just for backup reasons. Do you know that every repo (your working copy, that one onA, …) contains a full history of your development? It’s not like SVN where you have one central history. Git is a DVCS and every working copy has a full history.So, using Git, your history will only get lost if all repos get destroyed at the same time. Otherwise, you’ll always have at least one repo that contains your project history. See also the introduction chapter on Pro Git for some notes about that.