Git使用Heroku将当前分支推送到远程
我试图在Heroku上创建一个staging分支,但有一点我不太明白 假设我已经创建了heroku应用程序,并将remote设置为指向staging remote,如果我这样做:Git使用Heroku将当前分支推送到远程,git,heroku,production,staging,Git,Heroku,Production,Staging,我试图在Heroku上创建一个staging分支,但有一点我不太明白 假设我已经创建了heroku应用程序,并将remote设置为指向staging remote,如果我这样做: git checkout -b staging staging-remote/master 我得到了一个名为“staging”的本地分支,它跟踪staging remote/master——或者我就是这么想的 但是: 给我这个: remote staging Fetch URL: git@heroku.com:m
git checkout -b staging staging-remote/master
我得到了一个名为“staging”的本地分支,它跟踪staging remote/master——或者我就是这么想的
但是:
给我这个:
remote staging
Fetch URL: git@heroku.com:myappname.git
Push URL: git@heroku.com: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推送登台远程
我将把我的本地主分支推到暂存分支。但那不是我想要的。。。。基本上,我希望将更新合并到我的暂存分支中,然后轻松地将其推送到heroku,而不必像这样指定分支:
git push staging-remote mybranch:master
上面这一点并不难做到,但我希望避免意外地执行上一次推送操作并推送错误的分支。。。这对于我想要创建的生产分支来说是加倍重要的
我尝试过搞乱git配置,但还没有找到正确的方法…我想不出一个方法来实现这一点,但最后我找到了一个方便的rake任务来简化它: 从页面上,每个Git包含20个左右的命令: 似乎可以通过向本地git存储库添加一个config指令来实现您想要做的事情,例如:
git config remote.staging-remote.push mybranch:refs/remotes/staging-remote/master
然后,如果您从mybranch本地分支执行git push
,则应将其推送到登台远程的主分支
尽管如此,请使用git remote show staging remote进行验证,并在使用前仔细测试,因为我远不是git专家……我有一个名为heroku的分支,这对我很有用:
git config remote.heroku.push heroku:master
你面临的问题是heroku忽略了除master之外的所有分支。我在试图解决如何处理heroku忽略除“master”之外的所有分支的策略时遇到了同样的问题。如果您只能在Heroku上测试主分支,那么它就有点违背了保持独立分支的全部意义 这一限制的结果是,无论我在处理什么本地主题分支,我都希望有一种简单的方法将Heroku的主机切换到该本地主题分支,并在Heroku上执行“git push-f”以重写主机。不用说,拥有一个单独的远程存储库(如Github)是一个非常好的主意,可以在没有此限制的情况下备份所有内容。我会称之为“origin”,并使用“heroku”来表示heroku,这样“gitpush”总是支持所有内容 我从阅读《推送参考规范》一节中得到的是 git push heroku本地主题分支:refs/heads/master 我真正想要的是一种在配置文件中设置它的方法,这样“git push heroku”就可以始终执行上述操作,用我当前分支的名称替换“local topic branch” 我可能会问一个新问题,看看是否有其他人知道如何做到这一点。摘自《O'Reilly-Git版本控制》第184页第11章:远程存储库 在git推送操作期间,您通常希望提供并发布更改 你在你的本地主题分支上取得了成功。允许其他人在中查找您的更改 远程存储库上载它们后,您的更改必须作为主题分支显示在该存储库中。因此,在典型的gitpush命令期间,源从 您的存储库将使用refspec发送到远程存储库,例如:
+refs/heads/*:refs/heads/*
本参考规范可解释为:
从本地存储库中,获取在源命名空间下找到的每个分支名称
refs/heads/
并将其放置在目标下类似命名的匹配分支中
远程存储库中的命名空间refs/heads/
。
第一个refs/heads/
引用您的本地存储库(因为您正在执行推送),
第二个是指远程存储库。星号确保所有分支
它们是复制的。
这就是朱巴的例子失败的原因。修正后的参考规范应为:
git config remote.staging-remote.push +refs/heads/local_branch_name:refs/heads/master
我已经测试过了,@juba和@MatthewFord的版本工作得非常好
git config remote.staging.push staging:master
这会将名为staging的本地主题分支推送到名为staging的远程存储库上的远程分支master
@nickgrim将其放在一般形式中,如下所示:
git config remote.[remoteRepositoryName].push [localBranchName]:[remoteBranchName]
更新:
此外,当您使用-u
选项git push
时,现代git将方便地为您运行上述配置命令:
git push -u staging staging:master
这很有效。我已经多次使用它来设置具有git flow、heroku和备份git服务的客户端 .git/config用于回购:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[heroku]
account = youraccount
[remote "origin"]
url = git@bitbucket.org: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 = git@heroku.com:your-prod-app.git
push = master:master
[remote "staging"]
pushurl = git@heroku.com:your-staging-app.git
push = staging:master
所有工作正常:
git推送原点
git拉入原点
git推送暂存
git推送生产
把fetch和push想象成stdout和stdin,两者都可以重定向或关闭为单向。另外,如果有人知道如何在不破解.git/config的情况下获得这些设置,请随时修改,业力点肯定会随之而来
git-config-remote.heroku.push-HEAD:master
换句话说:>git-config-remote.[localBranchName].push[remoteName]:[remoteBranchName]@DavidAlpert:nope,这是反向的;您需要:git config remote.[remoteName].push[localBranchName]:[remoteBranchName]
对于简单推送,它给出了:git push localbranch remoteName:remotebranch@vinyll这是不对的。我想你的意思是:git-push-remotename-localbranch:remotebranch
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[heroku]
account = youraccount
[remote "origin"]
url = git@bitbucket.org: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 = git@heroku.com:your-prod-app.git
push = master:master
[remote "staging"]
pushurl = git@heroku.com:your-staging-app.git
push = staging:master