Git存储库同步

时间:2015-09-14 14:19:18

标签: git ssh git-bare

如何保持两个git存储库同步?

第一个存储库是一个" central"团队用于推送更改的存储库,在the git book guide之后创建。 第二个存储库只是第一个存储库的镜像

我将git与ssh一起使用,并且应该仅从第一个存储库推送更改,因为它位于安全网络之后。

1 个答案:

答案 0 :(得分:1)

Assuming the first repository knows about its mirror, you can use a post-receive hook. According to the manual, one of the common uses of such a hook is to notify others of a successfully received update.

To create such a hook, put a script (any script, the language/interpreter is determined by the shebang at the top) named post-receive in your hooks folder under .git (or under the main repo if it is bare). In the hook, run a command to push to the remote you are interested in. A sample script could be as follows:

#!/bin/sh
git push mirror

Here, mirror is the name of the mirror remote as configured in the main repository.