如何同步多个git存储库,包括标签和分支?
我在全国各地都有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该尽可能在服务器端进行,以免给提交者带来任何开销。您必须小心使用提交后挂钩的递归。如果所有服务器在提交时推送到所有其他服务器,则最终可能会出现所有服务器继续相互推送的情况。但是,您可以利用这一点来发挥自己的优势。每个服务器只需要关心它的虚拟服务器就可以了。例如,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.