简体   繁体   English

git从一个本地分支推送到两个在不同远程上具有不同名称的分支

[英]git push from one local branch to two branches with different names on different remotes

tl;dr: On git push I would like to achieve the following: tl; dr:git push我想实现以下目标:

local/staging -> wpengine-staging/master
local/staging -> gitlab/staging

local/master -> wpengine-production/master
local/master -> gitlab/master

Details: I am developing a site on https://wpengine.co.uk/ using their staging and production environments as well as their git push feature. 详细信息:我正在使用他们的暂存和生产环境以及git push功能在https://wpengine.co.uk/上开发一个网站。

Wpengine has production on a git repo/branch production/master and staging on a repo/branch staging/master . Wpengine在git repo / branch production/master上进行production/master并在repo / branch staging/master

To allow me to push to these respectively from one local repo with staging/master branches I have set up two remotes: wpengine-production and wpengine-staging . 为了使我可以从具有暂存/主分支的一个本地存储库分别推送这些数据,我设置了两个远程wpengine-productionwpengine-productionwpengine-staging

I then set the upstream for my local staging to wpengine-staging master and for my local master to wpengine-production master as well as git config push.default upstream 然后,我将本地staging的上游设置为wpengine-staging master ,将本地master的上游设置为wpengine-production master以及git config push.default upstream

So far so good - now when I git push from either branch it sends my commits to the desired remote and branch. 到目前为止一切顺利-现在,当我从任一分支进行git push ,它将提交提交到所需的远程分支。

Next I need to keep a copy of the code on a gitlab repo. 接下来,我需要在gitlab存储库上保留代码的副本。

For this my local repo should should push staging to gitlab/staging and master to gitlab/master . 为此,我的本地gitlab/staging应将登台推送到gitlab/staging ,将master推送到gitlab/master

Now, I am aware of Git - Pushing code to two remotes and that should work just fine for the master branch. 现在,我知道了Git-将代码推送到两个遥控器 ,这对于master分支应该可以正常工作。

I am however, struggling with the setup for the staging branch since, if I used two push URLs on a single remote, I would need to set two different upstreams on the same branch for each URL/branch. 但是,我正在为暂存分支的设置而苦苦挣扎,因为如果我在单个远程服务器上使用两个推送URL,则需要为每个URL /分支在同一分支上设置两个不同的上游。

As far as I can tell this isn't possible. 据我所知这是不可能的。

So setup wise I could have either: 因此,明智的设置是:

Two remotes with two push URLs each, let's call them production and staging : 两个具有两个推入URL的遥控器,我们称它们为productionstaging

production -> gitlab & wpengine-production

staging -> gitlab & wpengine-staging

Or, I could have three remotes, one for each URL: 或者,我可以有三个遥控器,每个URL一个:

gitlab , wpengine-staging , wpengine-production . gitlabwpengine-stagingwpengine-production

I know I could set an alias to push to two remote branches and that would be fine if it was just me but since others will be working on the project I really want to make this as fool proof as possible and enable this behaviour on git push. 我知道我可以设置一个别名以推送到两个远程分支,如果只是我,那会很好,但是由于其他人将在项目上工作,所以我真的想尽可能地做到这一点,并在git push上启用此行为。

As a side note - on git pull I need it to take from the wp-engine remotes but that part I don't have an issue with (I think). 附带说明-在git pull我需要它从wp-engine遥控器上获取,但是这一部分我没有问题(我认为)。

Finally, I am well aware that what I am trying to achieve probably isn't possible, and for good reasons (remotes should be explicitly stated on push / pull on complex setups like this). 最后,我很清楚,我试图实现的目标可能是不可能的,并且有充分的理由(在类似这样的复杂设置中,应该在push / pull中明确说明远程操作)。 The only reason I am exploring this is to avoid human error when working with this down the line. 我探索此问题的唯一原因是避免在进行此操作时出现人为错误。

I think this is what you need: 我认为这是您需要的:

Git - Pushing code to two remotes Git-将代码推送到两个遥控器

So basically you set up multile push url for the same remote, one for gitlab, one for the other, keeping all remotes synced. 因此,基本上,您为同一个遥控器设置了多重推送URL,一个为gitlab设置,另一个为另一个设置,使所有遥控器保持同步。

Or you can create server side hooks, so for example gitlab will push to the other one. 或者,您可以创建服务器端挂钩,例如gitlab将推送到另一个挂钩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 本地分支机构从一个地方拉到两个不同的远程站点和不同的分支机构(名称) - Local branches pulling from one place and pushing to two different remotes and in different branches(names) Git推送到具有2个不同分支的2个遥控器 - Git push to 2 remotes with 2 different branches 是否可以将分支推送到两个具有不同分支名称的遥控器? - Is it possible to push a branch to two remotes, each with different branch names? Git 从两个不同仓库的两个不同分支拉入一个本地分支 - Git pull from two different branches in two different repositories into one local branch git推送到多个遥控器上的不同分支 - git push to different branches on multiple remotes 如何在 Git 中合并来自两个不同遥控器的两个分支 - How to merge two branches from two different remotes in Git Git:两​​个子目录,如何从不同分支中拉出并推送到一个主分支 - Git: Two subdirectories, how to pull from different branches and push to one master branch 根据分支将git pull和push到不同的默认遥控器 - Having git pull and push to different default remotes based on the branch 从本地分支,git push到另一个远程分支 - From a local branch, git push to a different remote branch 单Git推送到带有两个不同配置文件的两个远程控制? - Single Git push to two remotes with two different Config files?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM