“git push heroku master”是如何实现的?知道推送到哪里以及如何推送到不同的存储库?
当推送到 Heroku 上托管的存储库时,必须执行以下命令:
git push heroku master
heroku
和 master
在此命令中表示什么? git 如何知道推送到哪里? (git 路径)
另外,我不知道我可以使用 heroku rename
来重命名应用程序,所以之前,假设我使用应用程序名称 trytryheroku 而现在我使用 heroku create real -thing
但如果我推送,它仍然会推送到 trytryheroku...有没有办法推送到真实的东西?
When pushing to a repository hosted on Heroku one must execute the following command:
git push heroku master
What do heroku
and master
indicate in this command? How does git know where to push to? (the git path)
Also, I didn't know I can use heroku rename
to rename an app, so before, say I was using the app name trytryheroku and now I use heroku create real-thing
but if I push, it still pushes to trytryheroku... is there a way to push to real-thing instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
“heroku”部分是您设置的遥控器的名称 - 当您第一次创建 Heroku 应用程序时,它会创建指向您的应用程序的 git 远程调用“heroku” - 如果您在项目中输入“git Remote”将向您显示远程端点。没有什么可以限制您使用“heroku”作为遥控器的名称 - 如果您的应用程序有多个环境,您可能有名为生产或登台的遥控器。
“master”部分是您希望推送到远程的本地分支。如果您在一个名为“myfeature”的功能分支中进行开发,并且您想将其部署到heroku,那么您可以这样做;
这里附加的 :master 是说将我的本地
myfeature
分支推送到远程的master
分支 - 注意:heroku 只能从 master 分支部署。如果您重命名应用程序,heroku git 远程 url 将更改 - 执行 git remote -v ,它将显示您的应用程序正在使用的 git 存储库,您可能需要删除旧的 Heroku 源并添加新的,
git remote rm heroku
然后git remote add heroku git@newgitpathfromcontrolpanel
要了解有关 Git 的更多信息,我建议 这本书
The 'heroku' part is the name of the remote that you have setup - when you create a heroku app the first time it creates a git remote call 'heroku' pointing at your application - if you type 'git remote' within your project it will show you the remote endpoints. There's nothing locking you into using 'heroku' as the name of the remote - if you have multiple environments for your application you may have remotes named production or staging for example.
The 'master' part is the local branch you wish to push to the remote. If you develop in a feature branch for example named 'myfeature' and you want to deploy that to heroku you would do;
the additional :master here is saying push my local
myfeature
branch into themaster
branch on the remote - note: heroku can only deploy from the master branch.If you rename an app the heroku git remote url will change - do a
git remote -v
which will show you the git repo your app is using, you will probably need to delete your old heroku origin and add the new one,git remote rm heroku
thengit remote add heroku git@newgitpathfromcontrolpanel
To learn more about Git I would recommend this book
第 1 部分:“git 如何知道推送到哪里?”
在执行上述命令之前:
总是需要执行一些其他步骤:安装 Git 和 Heroku、创建本地 Git 存储库、签名 -到heroku,通过命令行登录heroku,创建托管点的heroku句柄(在第2部分中解释)
1。本地 Git 存储库:
2.已注册 Heroku 并通过命令行登录:
因此,通过运行
$ git push heroku master
您已将代码/应用程序推送到 Heroku。第 2 部分:但是 heroku 和 master 表示什么?
这更像是一个 Git 问题,而不是 Heroku - Heroku 是一个托管平台,这取决于在Git(分布式版本控制系统)上进行部署。
“推送”的基本概念是将我们本地(在我们的工作计算机中)的某些内容(文件、应用程序等)推送到其他地方,在本例中推送到远程存储库(远程计算机)。
在 Git 中,在使用“push”之前,我们创建一个远程(句柄)作为对远程存储库(完整 URL)的引用,我们使用以下命令来实现:
“push”命令的基本结构是:
所以
$ git push heroku master
实际上是将您的代码/应用程序/文件(从某些本地 Git 存储库)推送到远程存储库 'heroku' 。想知道这个'heroku'远程是什么时候创建的,它是在您执行$ heroku create时添加的,
请注意最后一行“Git remote heroku added ”。
为了更清楚地说明,这里有一个用于检查/输出所有遥控器的 Git 命令:
$ git 远程 -v
将显示类似于以下内容的内容
因此我们可以假设当您执行 $ heroku create 时,在某处(隐式)执行了以下命令,从而创建了一些heroku存储库(url)的heroku远程*
PART 1 : "How does git know where to push to?"
Before executing the above mentioned command:
There are always few other steps to execute: Installing Git and Heroku, creating a local Git repo, signing-up to heroku, log-in heroku via command-line, creating heroku handle to hosting point (explained in PART 2)
1. A local Git repository:
2. Have sign-up(ed) for Heroku and logged-in via command-line:
So by running
$ git push heroku master
you have pushed the code/app to Heroku.PART 2: but what does heroku and master indicate?
It is more of a Git question than Heroku - Heroku is a hosting platform, which depends on Git (Distributed Version Control System) for deployment.
The basic concept of 'push' is pushing some thing (file, app, ..) we have locally (in our working machine) to somewhere else, in this case to a remote repository (remote machine).
In Git before using 'push' we create a remote (handle) which acts as a reference to a remote repository (Complete URL), we do so using the following command:
The basic structure of 'push' command is:
So
$ git push heroku master
is actually pushing your code/app/file (from some local Git repo) to a remote repo 'heroku' .wondering when this 'heroku' remote got created, it was added when you executed $ heroku create
Do notice the last line "Git remote heroku added".
to make it more clear, here's a Git command to check/output all the remotes:
$ git remote -v
will display something similar to the following
So we can assume that the following command was executed (implicitly) somewhere, when you did $ heroku create , hence creating the heroku remote to some heroku repo (url)*
heroku 需要作为 heroku gem 的一部分来协助推送,而 master 只是您要推送的 git 分支。 可以通过键入来查看,
git 知道推送到哪里,因为您创建了一个 heroku 应用程序,推送是自动设置的,如果您需要更改, 使用 git remote rm heroku 删除它,然后添加 yoru new使用
git Remote add heroku [email protected]:your- 的应用程序application-15.git
heroku is required as part of the heroku gem to assist with the push, and master is simply the git branch you are pushing. The git knows where to push to because you create a heroku application the push is automatically setup, which you can see by typing
if you need to change that remove it with
git remote rm heroku
and then add yoru new application withgit remote add heroku [email protected]:your-application-15.git
其他答案非常适合您问题的前半部分...
这是后半部分的简洁答案。
通过 https://devcenter.heroku.com/articles/重命名应用程序#updating-git-remotes
Other answers great for the first half of your question...
Here's the succinct answer to the second half.
via https://devcenter.heroku.com/articles/renaming-apps#updating-git-remotes
我找到了您可能对heroku感兴趣的答案:
https://dashboard.heroku .com/apps/NAMEOFYOURAPP/deploy/heroku-git
这样,heroku 就会知道要推送到哪里!
I found the answer you might be interested at heroku's:
https://dashboard.heroku.com/apps/NAMEOFYOURAPP/deploy/heroku-git
That way, heroku will know where to push!
就像你一样,我也很难理解 git 和 heroku 的这些细节,我也很困惑。但现在我已经有点清楚了,可以简短地回答你的问题了。
假设您的项目目录中有 git 设置。项目文件夹中存在一个 .git 隐藏文件夹,其中包含一个名为“config”的文件,该文件包含有关遥控器的所有信息。
远程是您单独命名的存储库,如 origin、heroku、staging、prod 等。
在您的命令中,heroku 代表您已映射到 heroku 项目的存储库。打开配置文件,您将看到 URL。
当您运行时,
您告诉 git 将当前原始存储库的 master 分支推送到 heroku 存储库的 master 分支
其余所有详细信息已在其他答案中共享,因此不想重复。所以这只是根据我的理解的简短答案。希望有帮助。
Just like you I also struggled to understand these nitty gritty of git and heroku and I was confused too. But now I have got bit of clarity to be able to answer your question in short.
Assuming you have git setup on your project directory. There exist a .git hidden folder in your project folder that contains a file named "config" this holds all information about remotes.
Remotes are your individual repositories named individually like origin, heroku, staging, prod etc..
In your command heroku stands for the repository you have mapped to heroku project. Open config file you will see the URL.
When you run
you're telling git to push your current origin repository's master branch to heroku repository's master branch
Rest all details are already shared in other answers so donot want to repeat. So this is just a short answer per my understanding. Hope it helps.