[英]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-production
: wpengine-production
和wpengine-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的遥控器,我们称它们为production
和staging
:
production -> gitlab & wpengine-production
staging -> gitlab & wpengine-staging
Or, I could have three remotes, one for each URL: 或者,我可以有三个遥控器,每个URL一个:
gitlab
, wpengine-staging
, wpengine-production
. gitlab
, wpengine-staging
, wpengine-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.