Git automatic post-receive hook

后端 未结 1 2064
小鲜肉
小鲜肉 2020-12-09 00:27

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-r

相关标签:
1条回答
  • 2020-12-09 01:17

    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.

    0 讨论(0)
提交回复
热议问题