【问题标题】:GIT isn't fetching my new branchGIT 没有获取我的新分支
【发布时间】:2015-04-24 04:41:06
【问题描述】:

我已经在我的遥控器上创建了一个新分支,所以我希望这样做:

$ git fetch && git checkout feature/name

但是,我收到此错误:

error: pathspec 'feature/name' did not match any file(s) known to git.

当我自己运行git fetch 时,它不会返回任何内容,我也尝试过git fetch origin,它也不起作用。

git remote 只返回一个名为origin 的遥控器。

我的配置如下所示:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = removed as it is a private repo
    fetch = +refs/heads/staging:refs/remotes/origin/staging
[branch "staging"]
    remote = origin
    merge = refs/heads/staging

【问题讨论】:

  • 你可以使用git pull
  • 但是我的分支还不存在。而且我还没有在我的本地仓库中创建分支,并且可能没有远程分支从其分支的原始分支。
  • 您的 origin.fetch 行不是 git 默认值。正常是remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
  • @AndrewC:这就是问题的原因;您应该将其添加为答案。
  • @torek - 这需要更多的工作:) 这个闻起来像复制品。

标签: git git-remote git-fetch


【解决方案1】:

解决方法是更正您的 remote.origin.fetch 参数,例如

git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'

所以可以获取所有分支。见:How to fetch all remote branches?

【讨论】:

    【解决方案2】:

    根据 Andrew C 的评论。我将 git 配置中的 fetch 行更改为:

    fetch=+refs/heads/*:refs/remotes/origin/*
    

    【讨论】:

      【解决方案3】:

      如果您在 GIt >1.9.X 上,您有一个默认上游,其值为 simple

      如果你想获取所有你应该使用的分支和标签:git fetch --all --prune
      --all 将获取所有分支和标签
      --prune 将删除所有删除的分支和标签

      这些标志将应用于您的本地存储库。

      【讨论】:

        猜你喜欢
        • 2020-07-24
        • 2021-03-20
        • 2021-04-29
        • 2014-11-02
        • 2012-07-22
        • 2021-02-03
        • 2013-03-21
        • 2017-12-23
        • 1970-01-01
        相关资源
        最近更新 更多