Heroku:如果你在Heroku上有多个应用程序,如何将代码推送到特定的应用程序?

10

我使用heroku create test-app3创建了一个新的Heroku应用程序。如果我想将一些代码推送到这个新的test-app3,我该如何做?

当我在终端中输入heroku list时,我会看到:

我的应用程序如下:

  • test-app1
  • test-app2
  • test-app3

我如何推送到test-app3? 我如何在不同的应用程序之间切换?

2个回答

24
你需要在Heroku为每个应用程序设置不同的git远程端点,这样你就可以从一个本地repo推送到任何一个应用程序。
通过仪表板获取Heroku应用程序的GIT URL(它看起来类似于这个:https://git@heroku.com:your_app_name.git),然后执行以下操作:
git remote add test-app1 https://git@heroku.com:test-app1.git

git remote add test-app2 https://git@heroku.com:test-app2.git

git remote add test-app3 https://git@heroku.com:test-app3.git

然后,您就可以像这样将代码推送到任何特定的应用程序:

git push test-app1 master

git push test-app2 master

git push test-app3 master

我一开始遇到了 fatal: Not a git repository 的问题,所以我输入了 git init 命令。但是现在,如果我输入 git remote add test-app1 命令,会出现 usage: git remote add [<options>] <name> <url> 的提示信息。我该怎么办? - JamesRocky
你的 git remote -v 命令输出是什么? - K M Rakibul Islam
你做了吗?git remote add test-app1 <在此处输入test-app1的gitrepo>? 然后当你执行:git remote -v 时,应该能够看到一些东西。 - K M Rakibul Islam
gitrepo,我没有做过那个。我没有 Github,那么我去哪里获取 gitrepo - JamesRocky
让我们在聊天中继续这个讨论。 - K M Rakibul Islam
你需要在 git URL 前面加上 https://,所以正确的 URL 是 https://git@heroku.com:test-app3.git。我已经更新了帖子以反映这一点。 - Arel

0

你可以通过终端导航到你的应用程序,使用cd test-app3命令,然后执行以下操作:

git add .
git commit -m "your message"
git push

最后:

git push heroku master 或者 git push heroku main,根据你的主分支名称而定。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接