git 同时使用 heroku 和 github
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15231937/
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
heroku and github at the same time
提问by K L
So I understand that heroku functions as a git repository, but let's say i want to use github as well as a repository. How do I set it up such that I have two repositories and both are in sync?
所以我知道 heroku 用作 git 存储库,但假设我想使用 github 和存储库。我如何设置它以便我有两个存储库并且两者都同步?
回答by Dan Hoerst
You can have multiple remotes on a git installation. You would have a github remote, and a heroku remote.
您可以在 git 安装上拥有多个遥控器。你会有一个 github 遥控器和一个 heroku 遥控器。
Assuming you already have github setup, then you probably push to github with something like:
假设您已经安装了 github,那么您可能会使用以下内容推送到 github:
git push origin master
git push origin master
origin
is your remote, and master
is your branch.
origin
是你的遥控器,master
是你的分支。
Follow the instructions in getting started with Herokuchoose your desired language and continue through the tutorial. This tutorial assumes that you already have github setup, and will show you how to create your heroku
remote - via heroku create
.
按照Heroku 入门中的说明选择您想要的语言并继续学习本教程。本教程假设您已经安装了 github,并将向您展示如何创建heroku
远程 - 通过heroku create
.
You then push to github as normal, and push to heroku via:
然后像往常一样推送到 github,并通过以下方式推送到 heroku:
git push heroku master
git push heroku master
The same format applies - heroku
is your remote, and master
is your branch. You are not overwriting your Github remote here, you are adding another, so you can still do both pushes via one commit with workflow such as:
相同的格式适用 -heroku
是您的遥控器,master
也是您的分支机构。您不是在这里覆盖您的 Github 遥控器,而是添加另一个遥控器,因此您仍然可以通过一次提交使用工作流程进行两次推送,例如:
git add .
git commit -m "Going to push to Heroku and Git"
git push origin master -- push to Github Master branch
git push heroku master -- push to Heroku
回答by 0xcaff
If you want to be able to push and pull to multiple remotes:
如果您希望能够推拉到多个遥控器:
First add them:
首先添加它们:
git remote add origin <github repo>
git remote add heroku [email protected]:<app name>.git
Then push
然后 push
git push origin master
git push heroku master
If you want to push to both remotes at the same time:
如果您想同时推送到两个遥控器:
Edit you configuration file so origin
points to both heroku and github:
编辑您的配置文件,以便同时origin
指向 heroku 和 github:
git config -e
Add/Replace:
添加/替换:
[remote "origin"]
url = [email protected]:username/somerepo.git
url = ssh://[email protected]/username/somerepo.git
Since you are using github you can integrate with heroku by navigating to:
由于您使用的是 github,您可以通过导航到以下位置与 heroku 集成:
https://dashboard.heroku.com/apps/<app name>/settings#github-repo
and adding your repository's name.
并添加您的存储库名称。
If you want to automatically push to heroku after committing to GitHub:
如果你想在提交到 GitHub 后自动推送到 heroku:
you will need to use a continuous integration platform like TravisCI.
您将需要使用像TravisCI这样的持续集成平台。
Here are the steps to make this work.Be careful what you push to production, make sure it works before it gets deployed. Each method has its pros and cons.
以下是完成这项工作的步骤。小心你推送到生产的东西,确保它在部署之前工作。每种方法都有其优点和缺点。
回答by Andrew Gorcester
I think this is actually the recommended case; the Heroku git repository function is really for deployment and not code management.
我认为这实际上是推荐的情况;Heroku git 存储库功能实际上是用于部署而不是代码管理。
Just use github to manage your code as usual, but additionally push to the Heroku git repository when you are ready to deploy. There is no need to keep them in sync with automated tools etc., because you want to be able to push to your github repository without deploying, for instance so that you can back up or collaborate on unfinished features or maintain separate staging and production environments.
只需像往常一样使用 github 管理您的代码,但在您准备部署时另外推送到 Heroku git 存储库。无需将它们与自动化工具等保持同步,因为您希望能够在不部署的情况下推送到您的 github 存储库,例如,以便您可以备份或协作处理未完成的功能或维护单独的暂存和生产环境.
回答by Richard Brown
I do this quite often. I create a site for Heroku but I want to keep my source in Github for archival purposes. I set up to remotes:
我经常这样做。我为 Heroku 创建了一个站点,但我想将我的源代码保存在 Github 中以用于存档目的。我设置为遥控器:
git remote add origin <github repo>
git remote add origin <github repo>
and
和
git remote add heroku <heroku repo>
git remote add heroku <heroku repo>
Then you can just git push origin master
and then git push heroku master
. Heroku also allows you to associate a github repo for the purposes of seeing commit diffs.
然后,你可以git push origin master
再git push heroku master
。Heroku 还允许您关联 github 存储库以查看提交差异。
回答by meeDamian
Since nobody mentioned that before. Git allows you now to add multiple urls to each remote. Just do it like this:
因为之前没人提过。Git 现在允许您向每个遥控器添加多个 url。只需这样做:
this will add fetch
and push
from github:
这将添加fetch
和push
来自 github:
git remote add origin [email protected]:yourName/yourGithubRepo.git
this will override github push
with heroku push
:
这将覆盖github push
有heroku push
:
git remote set-url origin --push --add [email protected]:yourHerokuRepo.git
this will re-add github push
:
这将重新添加github push
:
git remote set-url origin --push --add [email protected]:yourName/yourGithubRepo.git
and that's a final output:
这是最终的输出:
$ git remote -v
origin [email protected]:yourName/yourGithubRepo.git (fetch)
origin [email protected]:yourHerokuRepo.git (push)
origin [email protected]:yourName/yourGithubRepo.git (push)
After that just run:
之后只需运行:
git push
If, instead of working, it's saying sth about setting upstream, then type this first:
如果不是在工作,而是在说设置上游,那么首先输入:
git push --set-upstream origin master
回答by aandis
If you don't want to manage two repositories and just the one at Github, here's how you can do that (Assuming that you have already created an Heroku app).
如果您不想管理两个存储库,而只想在 Github 上管理一个存储库,那么您可以这样做(假设您已经创建了一个 Heroku 应用程序)。
1) First, clone the Heroku repository to your local.
1) 首先,将 Heroku 存储库克隆到您的本地。
2) Then create a Github repo and push this local there.
2) 然后创建一个 Github 存储库并将这个本地推送到那里。
3) Once that is done, use wercker
3)完成后,使用wercker
4) Goto "Add an Application" and fill in the details. They are fairly simple. Use the Github repository you just created.
4) 转到“添加应用程序”并填写详细信息。它们相当简单。使用您刚刚创建的 Github 存储库。
5) After adding the application goto Setting and add a Deploy Target. Select heroku from the list. And then select the Heroku app you had created eariler and branches you would like to push.
5) 添加应用程序后转到设置并添加部署目标。从列表中选择 heroku。然后选择您之前创建的 Heroku 应用程序和要推送的分支。
That's it! You're done. Now your Github repository is in sync with your Heroku application. Anything you push to the Github repo using
就是这样!你完成了。现在您的 Github 存储库与您的 Heroku 应用程序同步。您使用的任何推送到 Github 存储库的内容
git push origin master
will be automatically deployed to your Heroku application. This way you have your repository on Github to manage and you only have one repo to deal with. :)
将自动部署到您的 Heroku 应用程序。这样您就可以在 Github 上管理您的存储库,并且您只需处理一个存储库。:)