如何一次从多个分支中推动多个遥控器?

发布于 2025-02-04 06:05:20 字数 947 浏览 2 评论 0原文

因此,情况就是这样: 假设我在本地的git回购中有3个分支: Master dev 分期

现在,我为每个分支的服务器都有不同的服务器。 例如,我将 prods (prodserver)设置为遥控器,并将其映射到主(git push-set-upstream prods master)。因此,git push当我签到主人时,将主机推到prods。

相似地, devs dev 分支, stagings

当我的 dev staging 分期分支分支 当前检查,)我希望能够运行一个将 dev devs devs and staging stagings to stagings stagings dev >;与其必须切换到每个分支,然后运行git push或运行git push devs devs dev等等,因为我已经绘制了 dev to devs/dev

我知道可以将多个URL添加到遥控器中。但这不是 我要找的东西。说已经添加了多个遥控器 每个分支。但是我将它们添加到了一个特定的分支中,因为 我只想在这些遥控/s上的那个特定分支。那已经是 好的,工作。

Git本身有这样的选择吗?还是这里唯一的选择也许还有其他一些解决方法?

编辑:simpify,使理解问题变得更容易, 如果git Pull - All从所有本地分支跟踪的所有远程分支中拉出; git push不应该以类似的方式工作吗?

So, the situation is like this:
Say I have 3 branches in my local git repo: master, dev, staging.

Now, I have different servers for each branch that I want to push to.
For example I have set prodS (prodServer) as remote to master and have it mapped to master(git push -set--upstream prodS master). So that git push pushes master to prodS when I have checkedout master.

Similarly,
devS for dev branch,
stagingS for staging branch

When my dev and staging branches are ready for push, (Regardless of which branch I have currently checkedout,) I want to be able to run a single command that pushes dev to devS and staging to stagingS; instead of having to switch to each branch and then run git push or run git push devS dev and so forth for each branch since I already mapped dev to devS/dev.

I'm aware that multiple URLs can be added to a remote. But that is not
what I'm looking for. Say there are already multiple remotes added to
each of the branches. But I added them to a particular branch because
I want only that particular branch on those remote/s. That's already
ok and working.

Is there such an option in git itself? Or the only option here maybe some other workaround like a script?

EDIT: To simpify, and make it easier to understand the question,
If git pull --all pulls from all remote branches tracked by all local branches; shouldn't git push --all work in similar way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

睫毛溺水了 2025-02-11 06:05:20

我认为没有一个选项可以单个推动中的倍数遥控器指定多个分支,但是我认为有几个替代方案可能有用。

1。单个遥控器的多个推送URL:

如果您可以在dev stagings上分支 staging 分支在<代码> devs 然后,您可以定义一个新的远程&lt; name&gt;,并设置两个devsstagings的URL这个新遥控器的URL:

$ git remote set-url --add --push <name> <url-for-devS>
$ git remote set-url --add --push <name> <url-for-stagingS>

现在您可以使用git push&lt; name&gt;开发登台

2。别名

您可能已经知道这一点,但是您可以在.git/config file> file(甚至〜/.gitConfig)上设置新命令在别名部分下,您需要在多个项目上需要的东西,即使使用push> push命令,也可以将其用作git命令,例如-v-f

[alias]
    my-command = !git push devS dev $* && git push stagingS staging $*

现在,您可以运行git my -command -f

I don't think there is an option to specify multiple branches for multiples remotes in a single push, but I think there are a couple alternatives that might be useful.

1. Multiple push urls for a single remote:

If you are fine with having your dev branch on stagingS and your staging branch on devS then you can define a new remote <name> and set the urls for both devS and stagingS as push urls for this new remote:

$ git remote set-url --add --push <name> <url-for-devS>
$ git remote set-url --add --push <name> <url-for-stagingS>

Now you can push both dev and staging to both remotes with git push <name> dev staging

2. Aliases

You probably know this already, but you can set a new command on your .git/config file (or even ~/.gitconfig if this behaviour is something you need over multiple projects) under the alias section and you will be able to use it as a git command, even using normal flags for the push command like -v and -f.

[alias]
    my-command = !git push devS dev $* && git push stagingS staging $*

Now you can run git my-command -f, for example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文