“git push heroku master”如何知道推送到哪里以及如何推送到不同的存储库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5338551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:23:06  来源:igfitidea点击:

How does "git push heroku master" know where to push to and how to push to a different repo?

githeroku

提问by Sarah Wong

When pushing to a repository hosted on Heroku one must execute the following command:

当推送到 Heroku 上托管的存储库时,必须执行以下命令:

git push heroku master

What do herokuand masterindicate in this command? How does git know where to push to? (the git path)

在这个命令中做什么herokumaster指示什么?git 如何知道推送到哪里?(git路径)

Also, I didn't know I can use heroku renameto rename an app, so before, say I was using the app name trytryheroku and now I use heroku create real-thingbut if I push, it still pushes to trytryheroku... is there a way to push to real-thing instead?

另外,我不知道我可以heroku rename用来重命名应用程序,所以之前说我使用应用程序名称 trytryheroku,现在我使用heroku create real-thing但如果我推送,它仍然推送到 trytryheroku ......有没有办法推送到真实的东西?

回答by John Beynon

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.

'heroku' 部分是您设置的遥控器的名称 - 当您第一次创建 heroku 应用程序时,它会创建一个指向您的应用程序的 git 远程调用 'heroku' - 如果您在项目中输入 'git remote' 它将向您显示远程端点。没有什么可以限制您使用“heroku”作为远程的名称 - 例如,如果您的应用程序有多个环境,您可能有名为 production 或 staging 的远程。

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;

“master”部分是您希望推送到远程的本地分支。如果您在一个名为“myfeature”的功能分支中进行开发,并且您想将其部署到 heroku,您可以这样做;

git push heroku myfeature:master

the additional :master here is saying push my local myfeaturebranch into the masterbranch on the remote - note: heroku can only deploy from the master branch.

额外的 :master 是说将我的本地myfeature分支推送到master远程分支 - 注意:heroku 只能从主分支部署。

If you rename an app the heroku git remote url will change - do a git remote -vwhich 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 herokuthen git remote add heroku git@newgitpathfromcontrolpanel

如果你重命名一个应用程序,heroku git remote url 会改变 - 做一个git remote -v它会显示你的应用程序正在使用的 git repo,你可能需要删除旧的 heroku 源并添加新的,git remote rm heroku然后git remote add heroku git@newgitpathfromcontrolpanel

To learn more about Git I would recommend thisbook

要了解有关 Git 的更多信息,我会推荐本书

回答by Nabeel Ahmed

PART 1 : "How does git know where to push to?"

第 1 部分:“git 如何知道推送到哪里?”

Before executing the above mentioned command:

在执行上述命令之前:

$ git push heroku master

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)

总是有其他几个步骤需要执行:安装 Git 和 Heroku,创建本地 Git 存储库,注册到 heroku,通过命令行登录 heroku,创建到托管点的 heroku 句柄(在第 2 部分中解释

1. A local Git repository:

1. 本地 Git 存储库:

    $ 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. Have sign-up(ed) for Heroku and logged-in via command-line:

2. 注册 Heroku 并通过命令行登录:

$ 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

So by running $ git push heroku masteryou have pushed the code/app to Heroku.

因此,通过运行,$ git push heroku master您已将代码/应用程序推送到 Heroku。



PART 2: but what does herokuand masterindicate?

第 2 部分:但是herokumaster表示什么?

It is more of a Git question than Heroku - Heroku is a hosting platform, which depends on Git (Distributed Version Control System) for deployment.

它比 Heroku 更像是一个 Git 问题——Heroku 是一个托管平台,它依赖于 Git(分布式版本控制系统)进行部署。

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:

在使用“push”之前,在 Git 中,我们创建了一个远程(句柄)作为对远程存储库(完整 URL)的引用,我们使用以下命令进行操作:

$ git remote add <remote-name-of-our-choice> <URL-where-you-be-pushing-yourapp>

The basic structure of 'push' command is:

“push”命令的基本结构是:

$ git push <remote-name> <branch>

So $ git push heroku masteris actually pushing your code/app/file (from some local Git repo) to a remote repo 'heroku' .

所以$ git push heroku master实际上是将您的代码/应用程序/文件(从一些本地 Git 存储库)推送到远程存储库 'heroku' 。

wondering when this 'heroku' remote got created, it was added when you executed $ heroku create

想知道这个“heroku”遥控器是什么时候创建的,它是在您执行$ heroku create时添加的

$ 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

Do notice the last line "Git remote heroku added".

请注意最后一行“添加了 Git 远程 heroku”。

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

为了更清楚,这里有一个 Git 命令来检查/输出所有遥控器: $ git remote -v 将显示类似于以下内容

$ git remote -v
heroku     [email protected]:somerepo.git (fetch)
heroku     [email protected]:somerepo.git (push)

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 create 时,因此将 heroku 远程创建到某个 heroku repo (url)*

$ git remote add heroku [email protected]:somerepo.git

回答by Will Ayd

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

heroku 需要作为 heroku gem 的一部分来协助推送,而 master 只是您正在推送的 git 分支。git 知道推送到哪里,因为您创建了一个 heroku 应用程序,推送是自动设置的,您可以通过键入来查看

git remote -v

if you need to change that remove it with git remote rm herokuand then add yoru new application with git remote add heroku [email protected]:your-application-15.git

如果您需要更改删除它,git remote rm heroku然后添加您的新应用程序git remote add heroku [email protected]:your-application-15.git

回答by GollyJer

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

这是对后半部分的简洁回答。
通过https://devcenter.heroku.com/articles/renaming-apps#updating-git-remotes

git remote rm heroku
heroku git:remote -a name-of-heroku-app

回答by Sameer

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.

就像你一样,我也很难理解 git 和 heroku 的这些细节,我也很困惑。但是现在我有了一点清晰的认识,可以简短地回答您的问题。

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.

假设您的项目目录上有 git setup。在您的项目文件夹中存在一个 .git 隐藏文件夹,其中包含一个名为“config”的文件,该文件包含有关遥控器的所有信息。

Remotes are your individual repositories named individually like origin, heroku, staging, prod etc..

Remotes 是您单独命名的单独存储库,如 origin、heroku、staging、prod 等。

In your command heroku stands for the repository you have mapped to heroku project. Open config file you will see the URL.

在您的命令中 heroku 代表您映射到 heroku 项目的存储库。打开配置文件,您将看到 URL。

When you run

当你跑

git push heroku master

you're telling git to push your current origin repository's master branch to heroku repository's master branch

你告诉 git 将你当前的原始仓库的 master 分支推送到 heroku 仓库的 master 分支

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.

其余所有细节已在其他答案中共享,因此不想重复。所以根据我的理解,这只是一个简短的答案。希望能帮助到你。