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

发布于 2024-10-23 20:50:21 字数 350 浏览 1 评论 0原文

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

git push heroku master

herokumaster 在此命令中表示什么? 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

够钟 2024-10-30 20:50:21

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

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

git push heroku myfeature:master

这里附加的 :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;

git push heroku myfeature:master

the additional :master here is saying push my local myfeature branch into the master 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 then git remote add heroku git@newgitpathfromcontrolpanel

To learn more about Git I would recommend this book

回眸一遍 2024-10-30 20:50:21

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

在执行上述命令之前:

$ git push heroku master

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

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.已注册 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

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


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

这更像是一个 Git 问题,而不是 Heroku - Heroku 是一个托管平台,这取决于在Git(分布式版本控制系统)上进行部署。

“推送”的基本概念是将我们本地(在我们的工作计算机中)的某些内容(文件、应用程序等)推送到其他地方,在本例中推送到远程存储库(远程计算机)。

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

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

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

$ git push <remote-name> <branch>

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

想知道这个'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

请注意最后一行“Git remote heroku added ”。

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

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

因此我们可以假设当您执行 $ heroku create 时,在某处(隐式)执行了以下命令,从而创建了一些heroku存储库(url)的heroku远程*

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

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

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)

1. A local Git repository:

    $ 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:

$ 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 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:

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

The basic structure of 'push' command is:

$ git push <remote-name> <branch>

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

$ 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".

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 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)*

$ git remote add heroku [email protected]:somerepo.git
眼中杀气 2024-10-30 20:50:21

heroku 需要作为 heroku gem 的一部分来协助推送,而 master 只是您要推送的 git 分支。 可以通过键入来查看,

git remote -v

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

git remote -v

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

爱她像谁 2024-10-30 20:50:21

其他答案非常适合您问题的前半部分...

这是后半部分的简洁答案。
通过 https://devcenter.heroku.com/articles/重命名应用程序#updating-git-remotes

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

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

git remote rm heroku
heroku git:remote -a name-of-heroku-app
各自安好 2024-10-30 20:50:21

但是如果我推送,它仍然会推送到 trytryheroku...有没有办法推送到真实的东西?

我找到了您可能对heroku感兴趣的答案:

https://dashboard.heroku .com/apps/NAMEOFYOURAPP/deploy/heroku-git

$ cd my-project/
$ git init
$ heroku git:remote -a nameofyourapp

$ git add .
$ git commit -am "make it better"
$ git push heroku master

这样,heroku 就会知道要推送到哪里!

but if I push, it still pushes to trytryheroku... is there a way to push to real-thing instead?

I found the answer you might be interested at heroku's:

https://dashboard.heroku.com/apps/NAMEOFYOURAPP/deploy/heroku-git

$ cd my-project/
$ git init
$ heroku git:remote -a nameofyourapp

$ git add .
$ git commit -am "make it better"
$ git push heroku master

That way, heroku will know where to push!

澜川若宁 2024-10-30 20:50:21

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

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

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

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

当您运行时,

git push heroku master

您告诉 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

git push heroku master

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文