git创建分支并继承当前的上游 [英] git create branch and inherit upstream of current
问题描述
我使用以下命令创建一个新的本地分支 foo
git checkout --track -b foo
但是当它被创建时, .git / config
条目看起来像这样
[branchfoo]
远程=。
merge = refs / heads / master
只有一半是正确的,因为 remote
尚未设置为跟踪原始分支的远程(在我的情况下称为 upstream
),我使用 remote.pushdefault
,这样我从上游
并推到 origin
) 。
我也尝试直接使用 git branch
(创建后),例如
git分支-u上游/主要foo
,这似乎工作,但它意味着我需要每次手动键入上游/主要
部分动态...这是一个小事例)。
是否有命令有效地说将上游设置为当前上游?
我尝试更新它,例如
git branch -u`git rev-parse --abbrev-ref --symbolic-full-name @ {u} `foo
导致致命:branch'foo'不存在 code>。
更新这个hack似乎有用,但它很丑,所以我仍然喜欢更清洁的东西
[别名]
cut =!f(){UPSTREAM =`git rev-parse --abbrev-ref - git config branch。$ 1.pushremote origin;}; f
(第二部分是magit需要的)
创建一个别名来做到这一点
[别名]
cut =!f(){UPSTREAM =`git rev -parse --abbrev-ref --symbolic-full-name @ {u}`; git checkout -b $ 1 $ UPSTREAM; git config branch。$ 1.pushremote origin;}; f
第二部分是用于magit,因此您可以删除 git config分支。$ 1.p ushremote origin;
如果您不使用它。
I use the following to create a new local branch foo
git checkout --track -b foo
but when it is created, the .git/config
entry looks like this
[branch "foo"]
remote = .
merge = refs/heads/master
which is only half correct because the remote
has not been set to track the remote of the original branch (which is called upstream
in my case. I use remote.pushdefault
so that I pull from upstream
and push to origin
).
I've also tried using git branch
directly (after creating it), e.g. with
git branch -u upstream/master foo
and that seems to work, but it means I need to type the upstream/master
part manually every time (which is actually dynamic... this is the trivial case).
Is there a command to effectively say "set the upstream to the current upstream"?
My attempts to update it, e.g. with
git branch -u `git rev-parse --abbrev-ref --symbolic-full-name @{u}` foo
result in fatal: branch 'foo' does not exist
.
UPDATE this hack seems to work, but it's ugly, so I'd still like something cleaner
[alias]
cut = "!f() { UPSTREAM=`git rev-parse --abbrev-ref --symbolic-full-name @{u}`; git checkout -b $1 $UPSTREAM; git config branch.$1.pushremote origin; }; f"
(the second part is needed for magit)
ok, seems I cooked up an alias to do this
[alias]
cut = "!f() { UPSTREAM=`git rev-parse --abbrev-ref --symbolic-full-name @{u}`; git checkout -b $1 $UPSTREAM; git config branch.$1.pushremote origin; }; f"
the second part is for magit, so you can drop git config branch.$1.pushremote origin;
if you don't use it.
这篇关于git创建分支并继承当前的上游的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!