Git 使用 Heroku 将当前分支推送到远程

发布于 2024-08-25 00:58:37 字数 1272 浏览 4 评论 0原文

我正在尝试在 Heroku 上创建一个暂存分支,但有些东西我不太明白。

假设我已经创建了一个heroku应用程序并将遥控器设置为指向staging-remote,如果我这样做:

git checkout -b staging staging-remote/master

我会得到一个名为“staging”的本地分支,它跟踪staging-remote/master - 或者这就是我的想法......

但是:

git remote show staging-remote

给了我这个:

remote staging
  Fetch URL: [email protected]:myappname.git
  Push  URL: [email protected]:myappname.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    staging-remote merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

正如你所看到的,拉动看起来合理,但默认的推力却不然。这意味着如果我这样做:

git push staging-remote

我会将本地 master 分支推送到 staging 分支。但这不是我想要的......基本上,我想将更新合并到我的暂存分支中,然后轻松地将其推送到heroku,而不必像这样指定分支:

git push staging-remote mybranch:master

上面的操作并不难,但我想避免意外地执行先前的推送并推送错误的分支...这对于我想要创建的生产分支来说非常重要!

我试过搞乱 git config,但还没想出如何解决这个问题......

I'm trying to create a staging branch on Heroku, but there's something I don't quite get.

Assuming I've already created a heroku app and setup the remote to point to staging-remote, If I do:

git checkout -b staging staging-remote/master

I get a local branch called 'staging' which tracks staging-remote/master - or that's what I thought....

But:

git remote show staging-remote

Gives me this:

remote staging
  Fetch URL: [email protected]:myappname.git
  Push  URL: [email protected]:myappname.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    staging-remote merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

As you can see, the pull looks reasonable, but the default push does not. It implies that if I do:

git push staging-remote

I'm going to push my local master branch up to the staging branch. But that's not what I want.... Basically, I want to merge updates into my staging branch, then easily push it to heroku without having to specify the branch like so:

git push staging-remote mybranch:master

The above isn't hard to do, but I want to avoid accidentally doing the previous push and pushing the wrong branch... This is doubly important for the production branch I'd like to create!

I've tried messing with git config, but haven't figured out how to get this right yet...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(7

苍白女子 2024-09-01 00:58:37

我已经测试过了,@juba 和 @MatthewFord 的版本运行完美!

git config remote.staging.push staging:master

这会将名为 staging 的本地主题分支推送到名为 staging 的远程存储库上的远程分支 ma​​ster 中。

@nickgrim 将它的通用形式如下:

git config remote.[remoteRepositoryName].push [localBranchName]:[remoteBranchName]

更新:

此外,当您使用 -git Push 时,现代 git 将方便地为您运行上述配置命令u 选项:

git push -u staging staging:master

I have tested it and @juba and @MatthewFord's versions work perfectly!

git config remote.staging.push staging:master

This pushes my local topic branch named staging into remote branch master on the remote repository named staging.

@nickgrim put it in the general form like so:

git config remote.[remoteRepositoryName].push [localBranchName]:[remoteBranchName]

Update:

Furthermore, modern git will conveniently run the above configuration command for you when you git push with the -u option:

git push -u staging staging:master
梦毁影碎の 2024-09-01 00:58:37

我有一个名为heroku的分支,这对我有用:

git config remote.heroku.push heroku:master

您面临的问题是heroku忽略除master之外的所有分支。

I have a branch called heroku, and this worked for me:

git config remote.heroku.push heroku:master

the problem you're facing is heroku ignores all branches other than master.

っ左 2024-09-01 00:58:37

摘自《O'Reilly - 使用 Git 进行版本控制》一书第 184 页 |第 11 章:远程存储库

在 git Push 操作期间,您通常希望提供并发布更改
您在本地主题分支上制作的。为了让其他人能够发现您的更改
上传远程存储库后,您的更改必须作为主题分支显示在该存储库中。因此,在典型的 git push 命令期间,源分支来自
您的存储库将使用 refspec 发送到远程存储库,例如:

<前><代码>+refs/heads/*:refs/heads/*

这个参考规范可以解释为:
从本地存储库中,获取源命名空间下找到的每个分支名称
refs/heads/ 并将其放置在目标下的类似名称的匹配分支中
远程存储库中的命名空间refs/heads/
第一个 refs/heads/ 指的是您的本地存储库(因为您正在执行推送),
第二个是指远程存储库。星号确保所有分支
被复制。
...


这就是为什么朱巴的例子应该失败的原因。更正后的 refspec 应该是:

git config remote.staging-remote.push +refs/heads/local_branch_name:refs/heads/master

From the book "O’Reilly - Version Control with Git" page 184 | Chapter 11: Remote Repositories

During a git push operation, you typically want to provide and publish the changes
you made on your local topic branches. To allow others to find your changes in the
remote repository after you upload them, your changes must appear in that repository as topic branches. Thus, during a typical git push command, the source branches from
your repository are sent to the remote repository using a refspec such as:

+refs/heads/*:refs/heads/*

This refspec can be paraphrased as:
From the local repository, take each branch name found under the source namespace
refs/heads/ and place it in a similarly named, matching branch under the destination
namespace refs/heads/ in the remote repository.
The first refs/heads/ refers to your local repository (because you’re executing a push),
and the second refers to the remote repository. The asterisks ensure that all branches
are replicated.
...


That’s why the example from juba should fail. the corrected refspec should be:

git config remote.staging-remote.push +refs/heads/local_branch_name:refs/heads/master
寻找一个思念的角度 2024-09-01 00:58:37

Everiday Git with 20 个命令左右 页面:

http://www.kernel.org/pub/software/scm/git/docs/everyday.html

看来你可以通过在本地添加一个配置指令来实现你想要做的事情git 存储库,类似于:

git config remote.staging-remote.push mybranch:refs/remotes/staging-remote/master

然后,如果您从 mybranch 本地分支执行 git Push,它应该被推送到 master 分支您的staging-remote遥控器。

尽管如此,请使用 git remote show staging-remote 进行验证,并在使用之前仔细测试它,因为我距离 git 专家还很远......

From the page Everiday Git with 20 commands or so :

http://www.kernel.org/pub/software/scm/git/docs/everyday.html

It seems that you can achieve what you want to do by adding a config directive to your local git repository, something like :

git config remote.staging-remote.push mybranch:refs/remotes/staging-remote/master

Then, if you do a git push from your mybranch local branch, it should be pushed to the master branch of your staging-remote remote.

Nevertheless, please verify with git remote show staging-remote and carefully test it before using it, as I'm far from a git expert...

如痴如狂 2024-09-01 00:58:37

我无法找到一种方法来做到这一点,但最终我找到了一个方便的 rake 任务来使它变得简单:
http://www.jbarnette.com/2009/11/ 10/部署到heroku.html

I couldn't figure out a way to do this, but in the end I found a handy rake task to make it easy:
http://www.jbarnette.com/2009/11/10/deploying-to-heroku.html

初心 2024-09-01 00:58:37

我遇到了同样的问题,试图弄清楚如何处理 Heroku 忽略除“master”之外的所有分支的政策。如果你只能在 Heroku 上测试主分支,那么它有点违背了保留单独分支的全部意义。

这种限制的结果是,无论我正在处理哪个本地主题分支,我都希望有一种简单的方法将 Heroku 的 master 切换到该本地主题分支,并执行“git push -f”来覆盖 Heroku 上的 master 。不用说,拥有一个单独的远程存储库(如 Github)是一个非常好的主意,可以在不受此限制的情况下备份所有内容。我将其称为“origin”,并使用 Heroku 的“heroku”,以便“git Push”始终备份所有内容。

我从阅读 http://progit.org/book/ 的“Pushing Refspecs”部分得到了什么ch9-5.html

git push heroku local-topic-branch:refs/heads/master

我真正想要的是一种在配置文件中设置它的方法,以便“git push heroku”始终执行上面,将“local-topic-branch”替换为我当前分支的名称。

我可能会问这个新问题,看看其他人是否已经弄清楚如何做到这一点。

I'm having the same problem trying to figure out how to deal with Heroku's policy of ignoring all branches but 'master'. It kinda defeats the whole point of keeping separate branches if you can only ever test the master branch on Heroku.

The consequence of this restriction is that whatever local topic branch I may be working on, I'd like an easy way to switch Heroku's master to that local topic branch and do a "git push -f" to over-write master on Heroku. Needless to say, it would be a very good idea to have a separate remote repository (like Github), to back everything up without this restriction. I'd call that one "origin" and use "heroku" for Heroku so that "git push" always backs up everything.

What I got from reading the "Pushing Refspecs" section of http://progit.org/book/ch9-5.html is

git push heroku local-topic-branch:refs/heads/master

What I'd really like is a way to set this up in the config file so that "git push heroku" always does the above, replacing "local-topic-branch" with the name of whatever my current branch happens to be.

I may ask this as a new question, to see if anyone else has figured out how to do this.

情丝乱 2024-09-01 00:58:37

这有效。我已经多次使用它来设置带有 git-flow、heroku 和备份 git 服务的客户端。

存储库的 .git/config:

[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
  ignorecase = true
[heroku]
  account = youraccount
[remote "origin"]
  url = [email protected]:youruser/yoursite.heroku.com.git # or github, etc.
  fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
  remote = origin
  merge = refs/heads/master
[branch "staging"]
  remote = origin
  merge = refs/heads/staging
[branch "develop"]
  remote = origin
  merge = refs/heads/develop
[remote "production"]
  pushurl = [email protected]:your-prod-app.git
  push = master:master
[remote "staging"]
  pushurl = [email protected]:your-staging-app.git
  push = staging:master

一切正常:

git Push origin

git pull origin

git Push staging

git Push Production

将 fetch 和 push 想象成 std​​out 和 stdin,两者都可以以一种方式重定向或关闭。另外,如果有人知道如何在不破解 .git/config 的情况下获取这些设置,请随时进行编辑修改,业力点肯定会随之而来。

This works. I have used it more than a few times for setting up clients with git-flow, heroku, and a backup git service.

.git/config for the repo:

[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
  ignorecase = true
[heroku]
  account = youraccount
[remote "origin"]
  url = [email protected]:youruser/yoursite.heroku.com.git # or github, etc.
  fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
  remote = origin
  merge = refs/heads/master
[branch "staging"]
  remote = origin
  merge = refs/heads/staging
[branch "develop"]
  remote = origin
  merge = refs/heads/develop
[remote "production"]
  pushurl = [email protected]:your-prod-app.git
  push = master:master
[remote "staging"]
  pushurl = [email protected]:your-staging-app.git
  push = staging:master

All working correctly:

git push origin

git pull origin

git push staging

git push production

Think about fetch and push as like stdout and stdin, where both can be redirected or closed to be one way. Also if anyone knows how to get these settings without hacking .git/config, please feel free to amend with an edit, karma points are sure to follow.

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