如何从本地分支“X”隐式“git push”至“原点/Y”
假设您的源站上有一个分支,其名称长得可笑……
$> git branch -a
* master
origin/master
origin/branch-with-a-ridiculously-long-name
当您在本地处理该分支时,您想给它一个不那么荒谬的名称,例如 bob
。
$> git checkout origin/branch-with-a-ridiculously-long-name
$> git checkout -b bob
$> git branch --set-upstream bob origin/branch-with-a-ridiculously-long-name
当需要推送时,你能做什么,如果你运行:
$> git checkout bob
$> git push
那么“bob”上的任何本地更改都将被发送到“branch-with-a-ridiculously-long-name”,并且不会创建origin 上的新分支称为“bob”?
我实际上正在寻找一种使 git Push 隐式扩展为 git Push origin bob:branch-with-a-ridiculously-long-name 的方法。
我认为设置 git config push.default upload 可以部分解决问题,但我不确定如何处理本地分支的名称与远程分支的名称不同的事实。
Say you have a branch on your origin that has a ridiculously long name...
gt; git branch -a
* master
origin/master
origin/branch-with-a-ridiculously-long-name
And when you work on that branch locally, you want to give it a less ridiculous name, like bob
.
gt; git checkout origin/branch-with-a-ridiculously-long-name
gt; git checkout -b bob
gt; git branch --set-upstream bob origin/branch-with-a-ridiculously-long-name
When it comes time to push, what can you do such that if you run:
gt; git checkout bob
gt; git push
then any local changes on "bob" will be sent to the "branch-with-a-ridiculously-long-name", and won't create a new branch on origin called "bob"?
I'm effectively after a way of making git push
implicitly expand in to git push origin bob:branch-with-a-ridiculously-long-name
.
I think setting git config push.default upstream
goes part of the way, but I'm not sure how to deal with the fact that the local branch's name differs from the remote.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您将
push.default
设置为upstream
(或在 1.7.4.2 之前的 git 版本中设置tracking
),那么它应该完全符合您的要求您运行:... 或:
您运行的 gitbranch --set-upstream 命令与配置设置相结合,应该可以实现该功能。
我写了一篇关于这个的文章不幸的是 git push 和 git pull 之间的不对称。
If you set
push.default
toupstream
(ortracking
in versions of git before 1.7.4.2), that should do exactly what you want when you run:... or:
The
git branch --set-upstream
command that you ran, in combination with the config setting, should make that work.I wrote a post about this unfortunate asymmetry between git push and git pull.
这就是你所追求的吗?
http://markmcb.com/ 2008/09/21/multiple-remote-git-branches-with- different-local-names/
Is this what you're after?
http://markmcb.com/2008/09/21/multiple-remote-git-branches-with-different-local-names/
最新版本的 git(大多数 2.x 版本)包含在一个命令中设置所有此配置的选项:
这会将 bob 的上游设置为正确的远程分支。
或者,如果您已经有本地分支,则可以使用
--set-upstream-to
标志:这两者都将正确设置 git 配置
More recent versions of git (most 2.x versions) include the option to set all of this configuration in one command:
That will set the upstream of bob to the correct remote branch.
Alternatively if you have a local branch already, you can use the
--set-upstream-to
flag:Both of these will correctly set the git config