[英]git create branch and inherit upstream of current
I use the following to create a new local branch foo
我使用以下命令创建一个新的本地分支
foo
git checkout --track -b foo
but when it is created, the .git/config
entry looks like this 但是创建后,
.git/config
条目如下所示
[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
). 这是正确的一半,因为尚未将
remote
设置为跟踪原始分支的remote(在我的情况下称为upstream
。我使用remote.pushdefault
以便从upstream
拉出并推入origin
)。
I've also tried using git branch
directly (after creating it), eg with 我也尝试过直接使用
git branch
(在创建它之后),例如
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). 似乎可行,但这意味着我每次都需要手动键入
upstream/master
部件(实际上是动态的……这很简单)。
Is there a command to effectively say "set the upstream to the current upstream"? 是否有一条命令可以有效地说“将上游设置为当前上游”?
My attempts to update it, eg with 我尝试更新它,例如
git branch -u `git rev-parse --abbrev-ref --symbolic-full-name @{u}` foo
result in fatal: branch 'foo' does not exist
. 导致
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;
git config branch.$1.pushremote origin;
第二部分用于magit,因此您可以删除git config branch.$1.pushremote origin;
if you don't use it. 如果您不使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.