如何同步多个git存储库,包括标签和分支?

发布于 2024-12-03 04:42:55 字数 376 浏览 0 评论 0原文

我在全国各地都有 git repo 服务器。当我移动到这些位置之一时,我想使用本地服务器进行推/拉。只需修改 .git/config 并更改原始分支即可管理此操作。同时,我希望推送到该本地服务器的所有分支和标签都可以在其他服务器上的所有 git 存储库中复制。

设置此功能的最佳方法是什么?

我是否应该修改 .git/config 以包含具有每个服务器 url 的远程“all”?这样,每次我执行 git push all 时,它都会推送到所有服务器。

我是否应该向每个 git repo 服务器添加提交后挂钩以推送到其他服务器?这样就不需要客户端进行额外的设置,因为它们只需推送到任何服务器即可。

git clone --mirror 怎么样?这是否有助于实现聚类效果?

I have git repo servers at different locations around the country. When I move to one of those locations, I'd like to use the local server for push/pull. This is managed simply by modifying the .git/config and changing the origin branch. At the same time, I'd like all branches and tags pushed to that local server to be replicated across all the git repositories on other servers.

What is the best way to go about setting this up?

Should I modify the .git/config to include a remote "all" that has the url to each server? This way every time I do a git push all it will push to all servers.

Should I add in post-commit hooks to each git repo server to push to the other servers? This then requires no additional setup for the client side, as they simply need to push to any of the servers.

What about git clone --mirror? Will this help achieve the clustering effect?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮萍、无处依 2024-12-10 04:42:55

您应该尽可能在服务器端进行,以免给提交者带来任何开销。您必须小心使用提交后挂钩的递归。如果所有服务器在提交时推送到所有其他服务器,则最终可能会出现所有服务器继续相互推送的情况。但是,您可以利用这一点来发挥自己的优势。每个服务器只需要关心它的虚拟服务器就可以了。例如,A-> B-> C-> D-> ... A. 如果每个服务器都有一个提交后挂钩,首先查看下一个服务器是否是最新的,如果不是最新的,则推送它,然后最终所有服务器将同步。因此,服务器 A 推送到 B,B 推送到 C,C 推送到 D,D 检查 A 是否是最新的,因此不执行任何操作。

您可能会以这种方式结束边缘情况,并且必须担心推送到其他服务器失败,但下一次提交将同步它。

您也可以只使用 rsync。

You should do it server side as much as possible so as not to burden the committer with any overhead. You have to be careful about recursion with post commit hooks. If all servers push to all others on commit you can end up in a case where all severs continue to push to each other. However, you can use this to your advantage. Each server only needs to worry about the server to it's virtual right. For example, A -> B -> C -> D -> ... A. If each server has a post commit hook to first see if the next server is up to date and the push to it if not, push it then eventually all servers will be in sync. So server A pushed to B which pushes to C which pushes to D which checks to see that A is up to date so does nothing.

You'll probably end up with edge cases this way and have to worry about pushes that fail to other servers, but the next commit will sync it up.

You can also just use rsync.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文