3

假设你的起源上有一个分支,名字长得离谱......

$> 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 upstream是其中的一部分,但我不确定如何处理本地分支名称与远程分支名称不同的事实。

4

3 回答 3

4

如果您设置push.defaultupstream(或tracking在 1.7.4.2 之前的 git 版本中),那应该完全符合您运行时的要求:

   git push

... 或者:

   git push origin

您运行的git branch --set-upstream命令与配置设置相结合,应该可以使其正常工作。

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

于 2011-09-28T12:29:42.257 回答
1

这就是你所追求的吗? http://markmcb.com/2008/09/21/multiple-remote-git-branches-with-different-local-names/

于 2011-09-28T12:27:50.500 回答
0

最新版本的 git(大多数 2.x 版本)包括在一个命令中设置所有这些配置的选项:

git checkout -b bob origin/branch-with-a-ridiculously-long-name

这会将 bob 的上游设置为正确的远程分支。

或者,如果您已经有本地分支,则可以使用以下--set-upstream-to标志:

git checkout bob
git branch --set-upstream-to origin/branch-with-a-ridiculously-long-name

这两个都将正确设置 git config

于 2016-06-14T03:36:35.903 回答