简体   繁体   English

Git存储库同步

[英]Git repositories sync

How can I keep two git repository synced? 如何保持两个git存储库同步?

The first repository is a "central" repository used by the team to push changes, created following the git book guide . 第一个存储库是团队使用的“中央”存储库,用于推送根据git book指南创建的更改。 The second repository will be only a mirror of the first. 第二个存储库只是第一个存储库的镜像

I'm using git with ssh and changes should be pushed only from the first repository since it is behind a secured network. 我正在使用带有ssh的git,并且应该仅从第一个存储库推送更改,因为它位于安全网络之后。

Assuming the first repository knows about its mirror, you can use a post-receive hook. 假设第一个存储库知道它的镜像,你可以使用post-receive钩子。 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). 要创建这样一个钩子,在.git下的hooks文件夹中放置一个脚本(任何脚本,语言/解释器由顶部的shebang确定)命名为post-receive (如果它是裸的,则放在主repo下)。 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. 这里, mirror是主存储库中配置的镜像远程的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM