【问题标题】:Heroku: How to change a Git remote on HerokuHeroku:如何在 Heroku 上更改 Git 遥控器
【发布时间】:2011-09-07 18:48:42
【问题描述】:

我不想将我的应用上传到错误的域。

如何更改 git 上的 git master 分支?

【问题讨论】:

  • 是的。我创建了一个新的 heroku 应用程序:heroku create myapp。但是我在heroku上有另一个应用程序。我只想将 git master 更改为新应用程序。所以我可以说 git push heroku master。并且代码将被加载到新应用而不是旧应用。

标签: git heroku


【解决方案1】:

如果您正在使用heroku 遥控器(默认):

heroku git:remote -a [app name]

如果您想指定不同的遥控器,请使用-r 参数:

heroku git:remote -a [app name] -r [remote] 

编辑:感谢 Алексей Володько 指出没有必要删除旧遥控器。

【讨论】:

  • 刚刚遵循这种方法,似乎是当前正确的方法。
  • 由于 OP 没有指定正确答案,并且这个答案是对 OP 问题的总体回答,并且比上面的“顶级”答案有更多的赞成票,为什么这个答案仍然显示低于同意的答案?谢谢。
  • 甚至不需要删除旧的 git 遥控器。 heroku git:remote -a appname - 替换旧的就好了。
【解决方案2】:

假设您当前的遥控器名为origin,那么:

删除当前远程引用
git remote rm origin

添加新的遥控器

git remote add origin <URL to new heroku app>

推送到新域

git push -u origin master

-u 会将其设置为已跟踪。

【讨论】:

  • 我怎么知道我的起源是什么?
  • 你能解释一下你在这里的意思吗The -u will set this up as tracked.谢谢!
  • @uDay 表示当你请求拉取时,它会知道去取并合并这个分支
  • 我会更新这个答案以最初删除 heroku 远程 - 而不是 git remote origin master...
【解决方案3】:
  1. 查看远程 URL

    &gt; git remote -v

    heroku  https://git.heroku.com/###########.git (fetch) < your Heroku Remote URL
    heroku  https://git.heroku.com/############.git (push)
    origin  https://github.com/#######/#####.git (fetch) < if you use GitHub then this is your GitHub remote URL
    origin  https://github.com/#######/#####.git (push)
  1. 删除 Heroku 远程 URL

    &gt; git remote rm heroku

  2. 设置新的 Heroku 网址

    &gt; heroku git:remote -a ############

你就完成了。

【讨论】:

    【解决方案4】:

    这对我有用:

    git remote set-url heroku <repo git>
    

    这个替换旧网址heroku。

    您可以通过以下方式检查:

    git remote -v
    

    【讨论】:

      【解决方案5】:

      您可以拥有任意数量的分支,就像常规的 git 存储库一样,但根据 heroku 文档,master 以外的任何分支都将被忽略。

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

      被推送到 Heroku 的分支不是 主人将被忽略。如果你是 在当地的另一个分支机构工作, 你可以合并到 master 之前 推,或指定你想要 将本地分支推送到远程 主人。

      这意味着你可以推送任何你想要的东西,但是你在 heroku 上的应用总是指向 master 分支。

      但是,如果您对如何创建分支和使用 git 有疑问,您应该查看this other question

      【讨论】:

      • 如何更改 git master?
      • 你这是什么意思? change the git master 你的意思是更改文件,然后提交并推送到它?重命名它?你到底想做什么?
      • 刚刚看到您对这个问题的评论,您遇到了远程问题,而不是分支问题...查看@Abizern 的回答 :)
      【解决方案6】:

      如果您在 heroku 上有多个应用程序,并且想要向特定应用程序添加更改,请运行以下命令: heroku git:remote -a appname 然后运行以下命令。 1) 混帐添加。 2)git commit -m "changes" 3)git push heroku master

      【讨论】:

        【解决方案7】:

        这是通过 Git 文档找到的更好答案。

        这显示了 heroku 遥控器是什么:

        $ git remote get-url heroku

        在这里找到它:https://git-scm.com/docs/git-remote 如果您需要更改它,该文档中还有一个 set-url。

        【讨论】:

          【解决方案8】:

          如果您已经从终端使用 heroku 登录,请在终端中写入..
          heroku git:remote -a 应用名称

          【讨论】:

            猜你喜欢
            • 2023-03-10
            • 1970-01-01
            • 2017-04-23
            • 1970-01-01
            • 2014-03-12
            • 2012-12-09
            • 1970-01-01
            • 2017-05-23
            • 2013-02-09
            相关资源
            最近更新 更多