【问题标题】:How do I push all branches to one remote, and only individual branches to others?如何将所有分支推送到一个远程,而仅将单个分支推送到其他分支?
【发布时间】:2023-03-11 07:00:01
【问题描述】:

我有两个遥控器,publicprivate,还有两个分支,masterlearn

当我在master 上时,我希望git push 同时推送到publicprivate;当我在 learn 上时,我希望 git push 推送到 private

我试过git push --all private -u,但这似乎没有任何效果。


详细的,我已经完成了:

$ git remote remove public
$ git remote remove private
$ git remote add public https://github.com/.../A.git
$ git remote add private https://github.com/.../B.git
$ git push -u public master
Branch master set up to track remote branch master from public.
$ git push --all private -u
Branch learn set up to track remote branch learn from private.
Branch master set up to track remote branch master from private.

运行git branch -avv(手动将所有内容推送到每个分支后)给出:

* learn                  6489f4c [private/learn] ...
  master                 6489f4c [private/master] ...
  remotes/private/learn  6489f4c ...
  remotes/private/master 6489f4c ...
  remotes/public/master  6489f4c ...

【问题讨论】:

  • 我认为不可能为单次推送指定多个遥控器
  • 但是,您可以使用公共遥控器上的 post-receive 挂钩将它们链接起来,该挂钩会自动将 master 推送到您的私人遥控器。这样,您只需将 master 推送到 public,然后将其复制到 private。
  • @JeffPuckettII:这可能有效(特别是如果这是唯一的方法!)。你能详细说明一下吗?
  • @JeffPuckettII:另外,FWIW,我主要在Tower 工作,所以如果那里有可行的解决方案,我会喜欢的。
  • 因为您使用的是 Github,you can't run git hooks,只是他们用于 webhook 的 API。所以最简单的事情可能就是为两次推送创建一个别名。

标签: git git-push git-pull git-remote


【解决方案1】:

首先将你的远程仓库信息添加到 git 中

     git remote add origin https://github.com/gitachyut/a.git
     git remote add nonorigin https://github.com/gitachyut/b.git

这里的origin,nonorigin是repo别名的名字

推送时,定义repo名称,如下图

    git push origin master

    git push nonorigin testing

语法

    git push {repo alias name } { branch name }

【讨论】:

  • 你能解释一下这与这个问题有什么关系吗?
猜你喜欢
  • 2016-11-06
  • 2016-11-02
  • 2018-12-22
  • 1970-01-01
  • 1970-01-01
  • 2020-02-20
  • 2017-11-09
  • 2013-05-03
  • 2021-10-11
相关资源
最近更新 更多