Git automatic post-receive hook
I have three remote reposito开发者_Go百科ry 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 B
and Server C
is to backup Server A
, right?
In that case, you don't have to tell Server B
and Server C
to pull
from A
, instead push from A
to B
and C
. So the content of your post-receive hook would be
git push --mirror server_b
git push --mirror server_c
assuming that server_b
and server_c
are known remotes on A
. See the docs of git push
for a description of the --mirror
flag.
If you want B
and C
to become the active part, set up a cron job to git fetch A
periodically.
Another approach is to define a remote in your local repo that has three URLs:
[remote "multi"]
url = server_a/repo.git
url = server_b/repo.git
url = server_c/repo.git
Now, when you usually push your work to A
using git push
, simply do a
git push --mirror multi
to push all your local on A
, B
and C
at the same time.
Another question is: why do you push to B
and C
at all? It seems as you are doing it just for backup reasons. Do you know that every repo (your working copy, that one on A
, ...) 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.
精彩评论