How does “git push heroku master” know where to push to and how to push to a different repo?
当推送到Heroku上托管的存储库时,必须执行以下命令:
1 | git push heroku master |
此命令中
此外,我不知道可以使用
" heroku"部分是您已设置的遥控器的名称-首次创建heroku应用程序时,它会创建一个指向您的应用程序的git remote调用" heroku"-如果您在其中输入" git remote"您的项目将向您显示远程端点。没有什么可以阻止您使用" heroku"作为远程名称的-如果您的应用程序有多个环境,则可能会有名为production或staging的远程。
"主"部分是您希望推送到远程服务器的本地分支。如果您在名为" myfeature"的功能分支中进行开发,并且想要将其部署到heroku,则可以这样做;
1 | git push heroku myfeature:master |
这里的另外一个:master表示将我的本地
如果重命名一个应用程序,则heroku git远程URL将会更改-进行
要了解有关Git的更多信息,我会推荐这本书
部分1:" git如何知道要推送到哪里?"
在执行上述命令之前:
1 | $ git push heroku master |
总要执行其他几个步骤:安装Git和Heroku,创建本地Git存储库,注册到heroku,通过命令行登录heroku,创建托管点的heroku句柄(在第2部分中进行了说明)
1。本地Git存储库:
1 2 3 4 5 6 7 8 9 10 | $ git init Initialized empty Git repository in .git/ $ git add . $ git commit -m"my first commit" Created initial commit 5df2d09: my first commit 44 files changed, 8393 insertions(+), 0 deletions(-) create mode 100644 README create mode 100644 Procfile create mode 100644 app/controllers/source_file ... |
2。已注册Heroku,并通过命令行登录:
1 2 3 4 5 6 7 8 | $ heroku login Enter your Heroku credentials. Email: [email protected] Password: Could not find an existing public key. Would you like to generate one? [Yn] Generating new SSH public key. Uploading ssh public key /Users/adam/.ssh/id_rsa.pub |
因此,通过运行
部分2:但是heroku和master表示什么?
与其说是Heroku,不如说是一个Git问题-Heroku是一个托管平台,它依赖于Git(分布式版本控制系统)进行部署。
'push'的基本概念是将本地(在工作计算机中)拥有的某些东西(文件,应用程序,..)推送到其他地方,在这种情况下,将其推送到远程存储库(远程机器)。
在Git中使用"推"之前,我们创建一个远程(句柄)作为对远程存储库(完整URL)的引用,我们使用以下命令进行操作:
1 | $ git remote add <remote-name-of-our-choice> <URL-where-you-be-pushing-yourapp> |
'push'命令的基本结构为:
1 | $ git push <remote-name> <branch> |
因此
在创建此" heroku"遥控器时感到很奇怪,它是在执行$ heroku create
时添加的
1 2 3 4 | $ heroku create Creating stark-fog-398... done, stack is cedar http://stark-fog-398.herokuapp.com/ | [email protected]:stark-fog-398.git Git remote heroku added |
注意最后一行"添加了Git remote heroku"。
更清楚地说,这是一条Git命令,用于检查/输出所有遥控器:
$ git remote -v
将显示类似于以下内容的
1 2 3 | $ git remote -v heroku [email protected]:somerepo.git (fetch) heroku [email protected]:somerepo.git (push) |
因此,我们可以假定在执行$ heroku create时(隐式)在某处执行了以下命令,因此创建了某个heroku存储库(url)*
的heroku远程目录。
1 | $ git remote add heroku [email protected]:somerepo.git |
heroku是heroku gem的一部分,需要它来协助推送,而master只是您要推送的git分支。 git知道要推送到哪里,因为您创建了一个heroku应用程序,该推送是自动设置的,您可以通过键入
来查看
1 | git remote -v |
如果需要更改,请使用
添加yoru新应用程序
其他答案非常适合您问题的前半部分...
这是下半场的简洁答案。
通过https://devcenter.heroku.com/articles/renaming-apps#updating-git-remotes sub>
1 2 | git remote rm heroku heroku git:remote -a name-of-heroku-app |
but if I push, it still pushes to trytryheroku... is there a way to push to real-thing instead?
我找到了您可能对heroku感兴趣的答案:
https://dashboard.heroku.com/apps/NAMEOFYOURAPP/deploy/heroku-git
1 2 3 | $ cd my-project/ $ git init $ heroku git:remote -a nameofyourapp |
1 2 3 | $ git add . $ git commit -am"make it better" $ git push heroku master |
这样,heroku会知道往哪里推!
就像您一样,我也很难理解git和heroku的这些精妙之处,我也感到困惑。但是现在我已经很清楚可以简短地回答您的问题了。
假设您在项目目录上已安装git。您的项目文件夹中存在一个.git隐藏文件夹,其中包含一个名为" config"的文件,其中包含有关遥控器的所有信息。
Remote是您的各个存储库,分别命名为Origin,heroku,staging,prod等。
在您的命令中,heroku代表您已映射到heroku项目的存储库。打开配置文件,您将看到URL。
运行时
1 | git push heroku master |
您要告诉git将您当前的原始存储库的master分支推送到heroku存储库的master分支
其他所有答案都已经共享了,所以不想重复。因此,按照我的理解,这只是一个简短的答案。希望对您有所帮助。