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

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

How to link a folder with an existing Heroku app

githeroku

提问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 createcommand, 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 herokugit 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基于herokugit remote链接您的项目(以及其他一些选项,请参阅下面的更新)。要将 Heroku 远程添加为当前存储库中的远程,请使用以下命令:

git remote add heroku [email protected]:project.git

where projectis the name of your Heroku project (the same as the project.heroku.comsubdomain). Once you've done so, you can use the heroku xxxxcommands (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, projectis 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 herokufor the gem commands to work. I checked the source, and it appears it works like this:

正如 Ben 在评论中所提到的,不需要heroku为 gem 命令命名遥控器即可工作。我检查了 source,它似乎是这样工作的:

  1. If you specify an app name via the --appoption (e.g. heroku info --app myapp), it will use that app.
  2. If you specify a Git remotename via the --remoteoption (e.g. heroku info --remote production), it will use the app associated with that Git remote.
  3. If you specify no option and you have heroku.remoteset in your Git config file, it will use the app associated with that remote (for example, to set the default remote to "production" use git config heroku.remote productionin your repository, and Heroku will run git config heroku.remoteto read the value of this setting)
  4. If you specify no option, the gem finds no configuration in your .git/configfile, and the gem only finds one remote in your Git remotes that has "heroku.com" in the URL, it will use that remote.
  5. If none of these work, it raises an error instructing you to pass --appto your command.
  1. 如果您通过--app选项(例如heroku info --app myapp)指定应用程序名称,它将使用该应用程序。
  2. 如果您通过选项(例如)指定 Git远程名称,它将使用与该 Git 远程关联的应用程序。--remoteheroku info --remote production
  3. 如果您未指定任何选项并且您已heroku.remote在 Git 配置文件中进行设置,它将使用与该远程关联的应用程序(例如,将默认远程设置为git config heroku.remote production您存储库中的“生产”使用,并且 Heroku 将运行git config heroku.remote以读取该值此设置)
  4. 如果您不指定任何选项,gem 在您的.git/config文件中找不到任何配置,并且 gem 只会在您的 Git 遥控器中找到一个在 URL 中包含“heroku.com”的遥控器,它将使用该遥控器。
  5. 如果这些都不起作用,它会引发一个错误,指示您传递--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: remotecommand. 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

  1. 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
    
  2. Clone it local

    git clone [email protected]:youamazingapp.git
    
  3. Make a new repo on github and add it

    git remote add origin https://github.com/yourname/your_repo.git
    
  4. Push on github

    git push origin master
    
  1. 使用新的“heroku fork”命令!它将复制所有环境,之后您必须更新 github repo!

    heroku fork -a sourceapp targetapp
    
  2. 克隆到本地

    git clone [email protected]:youamazingapp.git
    
  3. 在github上新建一个repo并添加

    git remote add origin https://github.com/yourname/your_repo.git
    
  4. 在github上推送

    git push origin master
    

回答by Stranger

You should probable start ssh-agent and add your keys. Check this,

您应该可能启动 ssh-agent 并添加您的密钥。检查这个,

http://wordgraphs.com/post/5000/Heroku--Permission-denied--publickey---fatal--Could-not-read-from-remote-repository-

http://wordgraphs.com/post/5000/Heroku--Permission-denied--publickey---fatal--Could-not-read-from-remote-repository-

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:

它的文档是:

https://devcenter.heroku.com/articles/git

https://devcenter.heroku.com/articles/git

回答by maniragaba claude

for existing repository

对于现有存储库

type in terminal

输入终端

$ heroku git:remote -a example

$ heroku git:remote -a 示例

enter image description here

在此处输入图片说明