tl;dr:
On git push
I would like to achieve the following:
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.
Wpengine has production on a git repo/branch production/master
and staging on a 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
.
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
So far so good - now when I git push
from either branch it sends my commits to the desired remote and branch.
Next I need to keep a copy of the code on a gitlab repo.
For this my local repo should should push staging to gitlab/staging
and master
to gitlab/master
.
Now, I am aware of Git - Pushing code to two remotes and that should work just fine for the master branch.
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.
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
:
production -> gitlab & wpengine-production
staging -> gitlab & wpengine-staging
Or, I could have three remotes, one for each URL:
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.
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).
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). The only reason I am exploring this is to avoid human error when working with this down the line.