【问题标题】:Push code to more then one origin将代码推送到多个来源
【发布时间】:2012-10-16 03:18:41
【问题描述】:

我想做一个 git push,并且应该将更改推送到两个不同的来源。有没有办法用 git 的一个命令推送到多个来源?也许是一个不错的钩子?

【问题讨论】:

标签: git githooks git-push


【解决方案1】:

也许可以将此添加到您的.git/config

[alias]
push2 = ! git push remote1 && git push remote2

【讨论】:

    【解决方案2】:

    我使用了两种方法来做到这一点。当我有一个分叉的存储库和一个上游远程时,我发现一种方便的方法是使用远程上的pushurl 配置选项。就起源而言,它看起来像这样:

    [remote "origin"]
        url = git@github.com:user/repo.git
        pushurl = git@github.com:user/repo.git
        pushurl = git@github.com:me/repo.git
        fetch = +refs/heads/*:refs/remotes/origin/*
    

    在分叉存储库的情况下,我在upstream 远程中使用pushurl 技巧,并将其推送到我的分叉和上游存储库。它有助于使主分支保持同步而无需大惊小怪。

    我还在我的基础架构上托管的存储库上使用了接收后挂钩,以将它们镜像到其他地方(如 GitHub)。 post-receive 挂钩如下所示:

    nohup git push --mirror git@github.com:user/repo.git &> ~/.mirror.log
    

    然后我推送到服务器上的存储库,然后服务器推送到 GitHub 克隆。您需要确保正确设置了 SSH 密钥,但除此之外,这很容易。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-06
      • 2015-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-04
      • 1970-01-01
      相关资源
      最近更新 更多