自动镜像一个git仓库 [英] Automatically mirror a git repository

查看:256
本文介绍了自动镜像一个git仓库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用外部Subversion版本库的一个副作用是每次提交都会自动进行异地备份。



我想用Git实现同样的效果。

即对本地存储库的每一次提交都会自动提交给外部存储库,因此这两个存储库始终保持同步。



我想象一下post-commit钩子是要走的路。有没有人有这方面的具体例子?

解决方案

我为此写了一个post-commit钩子。钩本身很简单,只需在 .git / hooks / 目录中添加一个名为 post-commit 的文件,其内容如下:

  git push my_remote 



post-commit 文件应该是可执行文件。另外请确保您添加了合适的远程 my_remote 这个钩子才起作用。

我还制作了一个名为<$ c $的符号链接c>后合并,指向后提交。这是可选的。如果你这样做,你会在合并后自动同步。

更新:如果您想确保您的服务器和您的镜像不会不同步,并确保所有分支也都备份后,你的后提交钩子可以使用:

  git push my_remote -f --mirror 


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.

i.e. every commit to my local repository automatically commits to an external one so the two repositories are always in sync.

I imagine that a post-commit hook would be the way to go. Does anyone have any specific examples of this?

解决方案

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

这篇关于自动镜像一个git仓库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆