git 如何将不同的分支推送到不同的 Heroku 应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18264621/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:54:30  来源:igfitidea点击:

How do I push different branches to different heroku apps?

githerokugit-branchstagingdev-to-production

提问by Dave Sag

I've been working on a web-app that gets pushed to heroku. The source is hosted on GitHub.

我一直在开发一个被推送到 heroku 的网络应用程序。源代码托管在 GitHub 上。

So git pushpushes the master branch to GutHub.

因此git push将 master 分支推送到 GutHub。

My git branch 'master' is connected to Heroku app 'my-app-staging'

我的 git 分支 'master' 连接到 Heroku 应用程序 ' my-app-staging'

So git push herokupushes the app to my-app-staging.herokuapp.com

所以git push heroku将应用程序推送到my-app-staging.herokuapp.com

I've created a new Heroku app which will be the 'production' app, let's call it 'my-app-prod'.

我创建了一个新的 Heroku 应用程序,它将成为“生产”应用程序,我们称之为“ my-app-prod”。

I have created a branch now called 'production' (ie git checkout -b production) and I've run git push -u origin productionto make it a managed branch at GitHub.

我创建了一个现在称为“ production”(即git checkout -b production)的git push -u origin production分支,并且我已经运行以使其成为 GitHub 上的托管分支。

I now want to link the productionbranch to my-app-prod.herokuapp.comsuch that, when switched to the productionbranch I can simply type git push heroku(or perhaps git push prod-heroku productionor similar) and voila - the production branch is pushed to the production app.

我现在想将production分支链接到my-app-prod.herokuapp.com这样,当切换到production分支时,我可以简单地输入git push heroku(或者可能git push prod-heroku production或类似的内容),瞧 - 生产分支被推送到生产应用程序。

What's the recommended way to link my productionbranch to my-app-prodon Heroku?

将我的production分支链接到my-app-prodHeroku的推荐方法是什么?

I've wallowed through Heroku's own docs on thisbut they all assume I've set up my apps using the heroku createCLI, not set up my apps via Heroku's website, however the following paragraph just makes my head spin:

我已经浏览了Heroku 自己的文档,但他们都假设我已经使用heroku createCLI 设置了我的应用程序,而不是通过 Heroku 的网站设置我的应用程序,但是以下段落只是让我头晕:

It's simple to type git push staging masterand git push production masterwhen you've followed the steps above. Many developers like to take advantage of git's branches to separate in-progress and production-ready code, however. In this sort of setup, you might deploy to production from your master branch, merging in changes from a development branch once they've been reviewed on the staging app. With this setup, pushing is a littler trickier:

这是简单的输入git push staging mastergit push production master当你按照以上步骤操作。然而,许多开发人员喜欢利用 git 的分支来分离正在进行的代码和生产就绪的代码。在这种设置中,您可能会从主分支部署到生产,一旦在暂存应用程序上进行,就合并来自开发分支的更改。有了这个设置,推送就有点棘手了:

Where I want to end up is as follows:

我想结束的地方如下:

  1. In branch master: (a) git pushpushes code to GitHub, and (b) git push herokupushes code to my-app-stagingon Heroku
  2. In branch production: (c) git pushpushes code to the productionbranch on GitHub, and (d) git push herokupushes the productioncode to my-app-prodon Heroku.
  1. 在分支中master:(a)git push将代码推送到 GitHub,以及 (b)git push heroku将代码推送到my-app-stagingHeroku
  2. 在分支中production:(c)git push将代码推送到productionGitHub 上的分支,以及 (d)git push herokuproduction代码推送到my-app-prodHeroku 上。

Given step 1 above is already in place and step 2 (c) is in place, how do I achieve step 2 (d)?

鉴于上面的步骤 1 已经到位,步骤 2 (c) 已经到位,我如何实现步骤 2 (d)?

回答by akhanubis

You should add another remote for my-app-prod named prod-heroku (replace GIT_URL with the Git URL that you can find in the settings page of my-app-prod in heroku):

您应该为 my-app-prod 添加另一个名为 prod-heroku 的遥控器(将 GIT_URL 替换为您可以在 heroku 中 my-app-prod 的设置页面中找到的 Git URL):

git remote add prod-heroku GIT_URL
git push prod-heroku production:master

This will push your local branch production to the remote branch master in prod-heroku so my-app-prod will get deployed with the code in production branch.

这会将您的本地分支生产推送到 prod-heroku 中的远程分支 master,因此 my-app-prod 将与生产分支中的代码一起部署。