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
How do I push different branches to different heroku apps?
提问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 push
pushes 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 heroku
pushes 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 production
to make it a managed branch at GitHub.
我创建了一个现在称为“ production
”(即git checkout -b production
)的git push -u origin production
分支,并且我已经运行以使其成为 GitHub 上的托管分支。
I now want to link the production
branch to my-app-prod.herokuapp.com
such that, when switched to the production
branch I can simply type git push heroku
(or perhaps git push prod-heroku production
or 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 production
branch to my-app-prod
on Heroku?
将我的production
分支链接到my-app-prod
Heroku的推荐方法是什么?
I've wallowed through Heroku's own docs on thisbut they all assume I've set up my apps using the heroku create
CLI, not set up my apps via Heroku's website, however the following paragraph just makes my head spin:
我已经浏览了Heroku 自己的文档,但他们都假设我已经使用heroku create
CLI 设置了我的应用程序,而不是通过 Heroku 的网站设置我的应用程序,但是以下段落只是让我头晕:
It's simple to type
git push staging master
andgit push production master
when 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 master
和git push production master
当你按照以上步骤操作。然而,许多开发人员喜欢利用 git 的分支来分离正在进行的代码和生产就绪的代码。在这种设置中,您可能会从主分支部署到生产,一旦在暂存应用程序上进行,就合并来自开发分支的更改。有了这个设置,推送就有点棘手了:
Where I want to end up is as follows:
我想结束的地方如下:
- In branch
master
: (a)git push
pushes code to GitHub, and (b)git push heroku
pushes code tomy-app-staging
on Heroku - In branch
production
: (c)git push
pushes code to theproduction
branch on GitHub, and (d)git push heroku
pushes theproduction
code tomy-app-prod
on Heroku.
- 在分支中
master
:(a)git push
将代码推送到 GitHub,以及 (b)git push heroku
将代码推送到my-app-staging
Heroku - 在分支中
production
:(c)git push
将代码推送到production
GitHub 上的分支,以及 (d)git push heroku
将production
代码推送到my-app-prod
Heroku 上。
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 将与生产分支中的代码一起部署。