Automatically mirror a git repository

前端 未结 1 1910
情书的邮戳
情书的邮戳 2021-01-30 17:42

One of the side-effects of using an external Subversion repository was getting automatic offsite backups on every commit.

I\'d like to achieve the same using Git.

1条回答
  •  孤城傲影
    2021-01-30 18:32

    I wrote a post-commit hook for just this purpose. The hook itself is simple; just add a file named post-commit to your .git/hooks/ directory with the following contents:

    git push my_remote
    

    The post-commit file should be executable. Also make sure that you add a suitable remote repository with the name my_remote for this this hook to work.

    I also made a symlink named post-merge that points to post-commit. This is optional. If you do this you'll auto-sync after merges as well.

    UPDATE: If you want to ensure that your server, and your mirror do not get out of sync, and ensure that all branches are also backed up, your post-commit hook can use:

    git push my_remote -f --mirror
    

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