【问题标题】:git track branch with different namegit track 具有不同名称的分支
【发布时间】:2013-06-11 10:38:52
【问题描述】:

我有一个跟踪非默认分支的存储库。因此,有一个名为“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。为什么我不能只使用“推”?

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

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

【问题讨论】:

  • 你使用哪个 Git 版本?你设置push.default 选项了吗?
  • @GuillaumeDarmont 我已将信息添加到问题中
  • @GuillaumeDarmont 似乎解决方案是将push.default 更改为upstream。谢谢。
  • 酷。为其他用户添加了更简洁的答案。

标签: git git-branch


【解决方案1】:

好的。根据您添加的信息,我认为您只需将 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 Config(搜索push.default)。

【讨论】:

    【解决方案2】:

    使用 Git 2.20(2018 年第四季度),建议将略有变化。

    参见Ævar Arnfjörð Bjarmason (avar)commit 8247166(2018 年 11 月 13 日)。
    (由 Junio C Hamano -- gitster -- 合并于 commit 2c23f0b,2018 年 12 月 1 日)

    push: 更改不必要的模棱两可的例子错误

    b55e677 中添加的示例推送(“推送:引入新的push.default 模式“simple””,2012-04-24,v1.7.11-rc0)更改为无论当前设置是否为“simple”。

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

    让我们使用:

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

    【讨论】:

      猜你喜欢
      • 2011-04-26
      • 1970-01-01
      • 2018-02-06
      • 2020-01-24
      • 2019-11-20
      • 2016-05-14
      • 1970-01-01
      • 2016-12-07
      • 2012-04-06
      相关资源
      最近更新 更多