【问题标题】:How to setup git config for pushing to two different remote repositories from the same local repository?如何设置 git config 以从同一个本地存储库推送到两个不同的远程存储库?
【发布时间】:2017-12-28 04:09:52
【问题描述】:

过去几周我一直在使用 bitbucket 上的存储库从事一个项目。最近,我决定我也想要我的 github 帐户上的存储库。我已成功设置它,因此每次推送时,我都会推送到两个存储库。 github 存储库本质上是我对 bitbucket 存储库的提交的精确副本。我的问题是每次推送时我都必须为两个帐户输入我的姓名和用户名。

我已经研究了使用不同帐户的新条件包含,但似乎只有当存储库具有不同的文件路径时才有效,在这种情况下它们没有。

有谁知道设置我的 .git/config 文件的方法,以便它根据推送到的存储库自动使用特定的名称/电子邮件组合?

【问题讨论】:

标签: git github bitbucket


【解决方案1】:

您可以向您的项目添加 2 个来源,如下所示

git remote add origin origin_url.git
git remote add origin2 origin_url.git

每次对代码库进行更改后,使用 git commit -m "commit message"

然后推送到两个仓库,

git push origin master
git push origin2 master

这每次都会推送到您的两个存储库。

【讨论】:

    【解决方案2】:

    您的问题已在此处得到解答: Git: Pushing to two repos in one command
    所以基本上你必须添加你的额外存储库

    git remote set-url --add --push origin git@github.com:TEST/REPO.git
    

    (或者您可以使用 https 代替 ssh)。现在你已经准备好通过

    推送到两个 repos
    git push origin
    

    如果您使用的是 Bitbucket 或 Gitlab,它们还为您提供镜像存储库(取决于您的帐户类型)。在 Bitbucket 中也有很多可以镜像 GitHub 存储库的插件。

    【讨论】:

      猜你喜欢
      • 2017-02-23
      • 2019-09-18
      • 2011-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-12
      • 1970-01-01
      相关资源
      最近更新 更多