git 如何将文件夹与现有的 Heroku 应用程序链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5129598/
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 to link a folder with an existing Heroku app
提问by Kevin Pang
I have an existing Rails app on GitHub and deployed on Heroku. I'm trying to set up a new development machine and have cloned the project from my GitHub repository. However, I'm confused as to how to link this folder up to Heroku. Originally, I used the heroku create
command, but obviously I don't want to do that this time since it will create another Heroku instance.
我在 GitHub 上有一个现有的 Rails 应用程序并部署在 Heroku 上。我正在尝试设置一台新的开发机器并从我的 GitHub 存储库中克隆了该项目。但是,我对如何将此文件夹链接到 Heroku 感到困惑。最初,我使用了该heroku create
命令,但显然这次我不想这样做,因为它会创建另一个 Heroku 实例。
回答by Michelle Tilley
Herokulinks your projects based on the heroku
git remote (and a few other options, see the update below). To add your Heroku remote as a remote in your current repository, use the following command:
Heroku基于heroku
git remote链接您的项目(以及其他一些选项,请参阅下面的更新)。要将 Heroku 远程添加为当前存储库中的远程,请使用以下命令:
git remote add heroku [email protected]:project.git
where project
is the name of your Heroku project (the same as the project.heroku.com
subdomain). Once you've done so, you can use the heroku xxxx
commands (assuming you have the Heroku Toolbeltinstalled), and can push to Heroku as usual via git push heroku master
. As a shortcut, if you're using the command line tool, you can type:
project
您的 Heroku 项目的名称在哪里(与project.heroku.com
子域相同)。一旦你这样做了,你就可以使用heroku xxxx
命令(假设你已经安装了Heroku Toolbelt),并且可以像往常一样通过git push heroku master
. 作为一种快捷方式,如果您使用的是命令行工具,则可以键入:
heroku git:remote -a project
where, again, project
is the name of your Heroku project (thanks, Colonel Panic). You can name the Git remote anything you want by passing -r remote_name
.
再一次,这里project
是您的 Heroku 项目的名称(感谢Panic 上校)。你可以通过传递任何你想要的名字来命名 Git 远程-r remote_name
。
[Update]
[更新]
As mentioned by Ben in the comments, the remote doesn't need to be named heroku
for the gem commands to work. I checked the source, and it appears it works like this:
正如 Ben 在评论中所提到的,不需要heroku
为 gem 命令命名遥控器即可工作。我检查了 source,它似乎是这样工作的:
- If you specify an app name via the
--app
option (e.g.heroku info --app myapp
), it will use that app. - If you specify a Git remotename via the
--remote
option (e.g.heroku info --remote production
), it will use the app associated with that Git remote. - If you specify no option and you have
heroku.remote
set in your Git config file, it will use the app associated with that remote (for example, to set the default remote to "production" usegit config heroku.remote production
in your repository, and Heroku will rungit config heroku.remote
to read the value of this setting) - If you specify no option, the gem finds no configuration in your
.git/config
file, and the gem only finds one remote in your Git remotes that has "heroku.com" in the URL, it will use that remote. - If none of these work, it raises an error instructing you to pass
--app
to your command.
- 如果您通过
--app
选项(例如heroku info --app myapp
)指定应用程序名称,它将使用该应用程序。 - 如果您通过选项(例如)指定 Git远程名称,它将使用与该 Git 远程关联的应用程序。
--remote
heroku info --remote production
- 如果您未指定任何选项并且您已
heroku.remote
在 Git 配置文件中进行设置,它将使用与该远程关联的应用程序(例如,将默认远程设置为git config heroku.remote production
您存储库中的“生产”使用,并且 Heroku 将运行git config heroku.remote
以读取该值此设置) - 如果您不指定任何选项,gem 在您的
.git/config
文件中找不到任何配置,并且 gem 只会在您的 Git 遥控器中找到一个在 URL 中包含“heroku.com”的遥控器,它将使用该遥控器。 - 如果这些都不起作用,它会引发一个错误,指示您传递
--app
给您的命令。
回答by Colonel Panic
The Heroku CLIhas an easy shortcut for this. For an app named 'falling-wind-1624':
该Heroku的CLI有这样的一个简单的快捷键。对于名为“falling-wind-1624”的应用程序:
$ heroku git:remote -a falling-wind-1624
Git remote heroku added.
See https://devcenter.heroku.com/articles/git#creating-a-heroku-remote
见https://devcenter.heroku.com/articles/git#creating-a-heroku-remote
回答by Ghoti
Don't forget, if you are also on a machine where you haven't set up heroku before
别忘了,如果你也在一台之前没有设置过heroku的机器上
heroku keys:add
Or you won't be able to push or pull to the repo.
或者你将无法推送或拉到 repo。
回答by Rohit Sureka
Two things to take care while setting up a new deployment System for old App
为旧应用程序设置新部署系统时需要注意的两件事
1. To check your app access to Heroku (especially the app)
1. 检查您的应用程序对 Heroku 的访问(尤其是应用程序)
heroku apps
it will list the apps you have access to if you set up for the first time, you probably need to
如果您是第一次设置,它会列出您有权访问的应用程序,您可能需要
heroku keys:add
2. Then set up your git remote
2.然后设置你的git远程
For already created Heroku app, you can easily add a remote to your local repository with the heroku git: remote
command. All you need is your Heroku app's name:
对于已经创建的 Heroku 应用程序,您可以使用heroku git: remote
命令轻松地将远程添加到本地存储库。您所需要的只是您的 Heroku 应用程序的名称:
heroku git:remote -a appName
you can also rename your remotes with the git remote rename command:
您还可以使用 git remote rename 命令重命名您的遥控器:
git remote rename heroku heroku-dev(you desired app name)
then You can use the git remote command to confirm that a remote been set for your app
然后您可以使用 git remote 命令确认为您的应用程序设置了远程
git remote -v
回答by msroot
Use heroku's fork
使用 heroku 的 fork
Use the new "heroku fork" command! It will copy all the environment and you have to update the github repo after!
heroku fork -a sourceapp targetapp
Clone it local
git clone [email protected]:youamazingapp.git
Make a new repo on github and add it
git remote add origin https://github.com/yourname/your_repo.git
Push on github
git push origin master
使用新的“heroku fork”命令!它将复制所有环境,之后您必须更新 github repo!
heroku fork -a sourceapp targetapp
克隆到本地
git clone [email protected]:youamazingapp.git
在github上新建一个repo并添加
git remote add origin https://github.com/yourname/your_repo.git
在github上推送
git push origin master
回答by Stranger
You should probable start ssh-agent and add your keys. Check this,
您应该可能启动 ssh-agent 并添加您的密钥。检查这个,
It helped me.
它帮助了我。
回答by Diego Santa Cruz Mendezú
I've my project in github and heroku, for upload an heroku use :
我在 github 和 heroku 中有我的项目,用于上传 heroku 使用:
heroku git:remote -a <project>
The doc it is:
它的文档是: