如何隐式地从本地分支“G”推送“X”到“原点/ Y” [英] how to implicitly `git push` from a local branch "X" to "origin/Y"

查看:183
本文介绍了如何隐式地从本地分支“G”推送“X”到“原点/ Y”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设你的原产地有一个分支,它的名字很可笑......

git branch -a
* master
origin / master
origin / branch-with-a-ridiculously-long-name

当你在本地工作时,你想给它一个不太荒谬的名字,比如 bob 。 p>

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

我有效地使用 git push 隐式扩展为 git push origin bob:分支可用的长名称



我认为设置 git config push.default upstream 是其中的一部分,但我不确定如何处理事实上,本地分支的名称不同于远程。

解决方案

如果您设置 push.default

code>到上游(或者在1.7.4.2之前版本的git中<跟踪),那应该是正确的当你运行时你想要什么:

  git push 

...或者:

  git push origin 
code>

git分支--set-upstream 你运行的命令与配置设置结合起来应该可以起作用。



我写了一篇关于 git push和git pull之间的不对称

b $ b

Say you have a branch on your origin that has a ridiculously long name...

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

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

When it comes time to push, what can you do such that if you run:

$> git checkout bob
$> 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.

解决方案

If you set push.default to upstream (or tracking in versions of git before 1.7.4.2), that should do exactly what you want when you run:

   git push

... or:

   git push origin

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.

这篇关于如何隐式地从本地分支“G”推送“X”到“原点/ Y”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆