使用不同名称跟踪Git分支

18

我有一个跟踪非默认分支的代码库。因此,有一个名为“master”的本地分支应该跟踪“origin/master-13.07”。我已经执行了“push -u”,并且相信这应该足够了,该分支已被跟踪。运行git branch -vv的输出:

C:\work\repo>git branch -vv
  stuff     68792df [origin/stuff-13.07] Small bugfix
* master 68792df [origin/master-13.07: ahead 1] Small bugfix

git status的输出结果。

C:\work\repo>git status
# On branch master
# Your branch is ahead of 'origin/master-13.07' by 1 commit.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean

看起来一切都很顺利,但当我只使用 "git push"(如上面git建议我的方式)时,它失败了:

C:\work\repo>git push
fatal: The upstream branch of your current branch does not match
the name of your current branch.  To push to the upstream branch
on the remote, use

    git push origin HEAD:master-13.07

To push to the branch of the same name on the remote, use

    git push origin master

是的,我知道名称不匹配,这正是我想要的,并且我通过“push -u”告诉了git。为什么我不能只使用“push”?

C:\work\repo>git --version
git version 1.8.3.msysgit.0

C:\work\repo>git config push.default
simple

你使用哪个Git版本?你设置了push.default选项吗? - Guillaume Darmont
@GuillaumeDarmont 我已经在问题中添加了信息。 - kan
1
@GuillaumeDarmont 看起来解决方案是将 push.default 更改为 upstream。谢谢。 - kan
很好。为其他用户添加了一个更清晰的答案。 - Guillaume Darmont
2个回答

21

好的。根据您提供的信息,我认为您只需要将push.default更改为值upstream

您可能在升级Git并看到此消息后配置了实际值:

warning: push.default is unset; its implicit value is changing in 
Git 2.0 from 'matching' to 'simple'. To squelch this message 
and maintain the current behavior after the default changes, use: 

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use: 

  git config --global push.default simple

根据文档,simple 值必须在分支名称不同的情况下拒绝推送。请参阅 Git 配置(搜索 push.default)。


0

随着 Git 2.20(2018年第4季度)的到来,建议会略有变化。

请参见 提交 8247166(2018年11月13日),作者为 Ævar Arnfjörð Bjarmason(avar
(由Junio C Hamano -- gitster --提交 2c23f0b中合并,2018年12月1日)

push:更改错误的含糊示例

更改在b55e677(“push:引入新的push.default模式“simple””,2012-04-24,v1.7.11-rc0)中添加的示例push,以便无论当前设置是否为“simple”,它始终表示相同的含义。

此错误仅在“simple”下发出,但消息正在向用户解释他们可以通过这两个调用获得两种不同的行为。

让我们使用:

  • git push <remote> HEAD”,它始终表示将当前分支名称推送到该远程分支,
  • 而不是“git push <remote> <current-branch-name>”,在“simple”下会执行此操作,但不能保证在“upstream”下执行此操作。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接