我在GitHub上有一个现有的Rails应用程序,并已部署在Heroku上。我正在尝试设置一个新的开发机器,并从我的GitHub存储库克隆了该项目。然而,我对如何将此文件夹链接到Heroku感到困惑。最初,我使用了heroku create
命令,但显然这次我不想这样做,因为它会创建另一个Heroku实例。
Heroku会将你的项目基于heroku
git远程链接在一起(还有其他一些选项,请参见下面的更新)。要将Heroku远程作为当前存储库中的远程添加,请使用以下命令:
git remote add heroku git@heroku.com:project.git
在这里,project
代表你的 Heroku 项目的名称(与 project.heroku.com
子域相同)。完成后,你可以使用 heroku xxxx
命令(假设你已经安装了 Heroku Toolbelt),并通过 git push heroku master
像往常一样将代码推送到 Heroku。如果你正在使用命令行工具的话,可以使用以下快捷方式:
heroku git:remote -a project
在这里,project
是你的 Heroku 项目名称(感谢Colonel Panic)。你可以通过传递 -r remote_name
来任意命名 Git 远程库的名称。
[更新]
正如 Ben 在评论中提到的那样,远程库的名称不需要为 heroku
才能运行 gem 命令。我查看了源代码,它似乎是这样工作的:
--app
选项指定了应用名称(例如 heroku info --app myapp
),它将使用该应用。--remote
选项指定了 Git 远程库的名称(例如 heroku info --remote production
),它将使用与该 Git 远程库相关联的应用。heroku.remote
,它将使用与该远程库相关联的应用(例如,要将默认远程库设置为“production”,请在存储库中使用 git config heroku.remote production
命令,并且 Heroku 将运行 git config heroku.remote
以读取该设置的值)。.git/config
文件中找不到配置,且 gem 在您的 Git 远程库中只找到一个 URL 中包含 "heroku.com" 的远程库,则它将使用该远程库。--app
。Heroku CLI提供了一个简单的快捷方式。对于一个名为'falling-wind-1624'的应用程序:
$ heroku git:remote -a falling-wind-1624
Git remote heroku added.
请参考 https://devcenter.heroku.com/articles/git#creating-a-heroku-remote
! Resource not found
- Green-r other_remote_name
,您可以将远程命名为任何您想要的名称。 - MasterScrat将git远程设置为https://git.heroku.com/my-service.git
..现在该怎么办? - Sunil Garg不要忘记,如果你也在一台你之前没有设置Heroku的机器上
heroku keys:add
否则你将无法向仓库推送或拉取。
git remote add staging git@staging.xx:yy.git
和git remote add production git@production.xx:yy.git
--但这还不够。当我尝试执行git push staging master
(或production)时,我会收到“Permission denied(publickey)。fatal:The remote end hung up unexpectedly”的错误提示。解决这个错误的方法是像Ghoti提到的那样执行heroku keys:add
。 - Purplejacketheroku login
git init
heroku git:remote -a app-name123
然后检查远程仓库:
git remote -v
为旧应用程序设置新部署系统时需要注意两个事项
1.检查您的应用程序是否可以访问Heroku(特别是该应用程序)。
heroku apps
它将列出您可以访问的应用程序,如果您首次设置,可能需要
heroku keys:add
2. 然后设置你的git远程
如果已经创建了Heroku应用程序,您可以使用heroku git:remote
命令轻松地向本地存储库添加远程。您所需要的只是Heroku应用程序的名称:
heroku git:remote -a appName
你也可以使用 git remote rename 命令来重命名远程仓库:
git remote rename heroku heroku-dev(you desired app name)
然后,您可以使用git remote命令确认是否已为您的应用设置了远程仓库
git remote -v
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 git@heroku.com: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
我在Github和Heroku上有我的项目,上传到Heroku需要使用以下命令:
heroku git:remote -a <project>
这是文档:
heroku git:remote
方法,请检查您是否正在使用heroku toolbelt cli,并且您的系统上没有安装任何heroku gem(似乎在我使用旧的gems时无法正常工作)。 - Pierre-Adrienheroku git:remote -a project
- pansayheroku login
,则远程的格式为https://git.heroku.com/project-name.git
。 - max pleaner