Git推送到一个远程仓库,该仓库可部署到其他多个远程仓库 [英] Git push to one remote repo which deploys to multiple other remote repositories

查看:182
本文介绍了Git推送到一个远程仓库,该仓库可部署到其他多个远程仓库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在学习Git,并且只希望推送到我们的主Git服务器(git.example.com).哪些服务器必须(基于存储库)部署到其他服务器,例如我们的开发Web服务器(dev.example.com)和Redmine(redmine.example.com)项目管理服务器.

We are learning Git and would like to push only to our main Git server (git.example.com). Which must deploy (based on the repo) to other servers like our development webserver (dev.example.com) and Redmine (redmine.example.com) project management server.

我们知道,可以通过以下工作站上的小配置来实现:.git/config,例如:

We understand that this can be done by a small configuration in: .git/config on the workstations like:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = https://git.example.com/testing.git
    # Development server only needs to serve the files.
    url = https://dev.example.com/testing.git
    # Redmine must be a bare one.
    url = https://redmine.example.com/testing.git

我们对以上解决方案的看法.首先,这将消耗额外的带宽/上载.其次,我们不喜欢必须在客户端进行配置:.git/config.无论如何,至少要在git.example.com上进行配置吗?

Our opinion about above solution. First of all that would consume additional bandwidth/upload. Second we don't like that this must be configured on the client side: .git/config. Is there anyway to configure this at least on git.example.com?

对于有相同问题的任何人,此站点都对我们有很大帮助:

For anybody who has the same question this site did help us a lot: Website maintenance with git, the pro way. Small snippet which you can find on the bottom of that page:

根据您的需要,您可能需要调整此过程a 少量.假设您只想将更改推送到登台服务器 来自git.example.com上的裸仓库,而不是您的家中 电脑直接.您可以通过更改remote.staging.push来完成此操作 配置选项以读取 refs/remotes/origin/master:refs/heads/master代替 refs/heads/master:refs/heads/master.如果您有,这可能会很有用 需要能够推送到登台服务器的多个开发人员.

Depending on your needs, you might want to adjust this procedure a bit. Let's say you only want to push changes to the staging server from the bare repository on git.example.com, not from your home computer directly. You can do this by altering the remote.staging.push configuration option to read refs/remotes/origin/master:refs/heads/master instead of refs/heads/master:refs/heads/master. This might be useful if you have multiple developers who need to be able to push to the staging server.

我们不完全了解这种可能的解决方案.但是听起来这可以解决我们的问题.我们还将阅读Git文档,并会及时通知您.

We don't completely understand this possible solution. But sounds that it could be a solution for our problem. We are also reading through the Git documentation and will keep you guys posted.

我们非常感谢您的帮助.预先感谢.

Any help is really appreciated. Thanks in advance.

推荐答案

您可以使用服务器端挂钩脚本来完成此操作.在这种情况下,您希望添加到接收后挂钩,一旦接受更新并将其应用于服务器存储库并完成所有操作,该挂钩将运行.我通过将所有补丁重新应用到另一个仓库中,使用该钩子将git-tfs仓库镜像到具有更多历史记录的适当git仓库.为了您的目的,仅对每个目标调用git push --mirror就足够了.或者,您可以只在服务器上运行cron作业,以定期执行相同的操作.

You can do this using server side hook scripts. In this case you would want to add to the post-receive hook which is run once the update has been accepted and applied to the servers repository and everything is completed. I used this hook for mirroring a git-tfs repository into a proper git repository with more history by re-applying all patches to the other repo. For your purposes, just calling git push --mirror for each target would probably be enough. Or you could just run a cron job on the server to do the same thing at regular intervals.

样本后接收电子邮件钩子脚本显示了如何将目标存储库存储为配置变量,并在继续操作之前检查存储库是否处于明智状态,您的想法如何.钩子脚本的任何输出都可以显示给推送用户,如果由于任何原因而失败,这将有所帮助.

The sample post-receive-email hook script shows how fancy you can get with storing target repositories as config variables and checking that your repositories are in sensible states before you go ahead. Any output from the hook scripts can be shown to the pushing user which helps if things fail for any reason.

最简单的就是在我认为的服务器挂钩/接收后脚本中添加一些git push --mirror mirror1; git push --mirror redmine行.

Simplest will just be to add some git push --mirror mirror1; git push --mirror redmine lines to the servers hooks/post-receive script I think.

这篇关于Git推送到一个远程仓库,该仓库可部署到其他多个远程仓库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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