Git fetch无法下载远程分支

13

我无法让Git获取远程的新分支。git remote show不会显示除master以外存在任何分支,但是git ls-remote证明它们确实存在。

例如:git ls-remote显示分支homodyne_process存在-

$ git ls-remote origin
b935ee960a588144d3df0f08a82b81ea705c7543        HEAD
f11bd3ac9c2345a12edb9d49cd5bd027616b2226        refs/heads/homodyne_process
b935ee960a588144d3df0f08a82b81ea705c7543        refs/heads/master

获取更新并显示远程分支

$ git fetch
$ git remote show origin
* remote origin
  Fetch URL: gitolite@git.uio.no:***
  Push  URL: gitolite@git.uio.no:***
  HEAD branch: master
  Remote branch:
    master tracked
  Local branches configured for 'git pull':
    master        merges with remote master
  Local refs configured for 'git push':
    homodyne_process pushes to homodyne_process (fast-forwardable)
    master           pushes to master           (up to date)
$ git branch -r
  origin/master

我运行后成功获得了homodyne_process pushes (...)这一行。

git pull origin homodyne_process:homodyne_process

但它仍然不会显示远程分支的存在。为什么会发生这种情况?

我也尝试过任何git fetch origin homodyne_process和各种组合,但是分支origin/homodyne_process不会出现。

我正在Windows上工作,而存储库是通过gitolite托管的。

(为了简洁起见,我已从输出中删除了其他一些分支。)

1个回答

23
此回答解决了我的问题:https://dev59.com/KGgu5IYBdhLWcg3wDS0G#25941875
基本上我需要运行
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"

这将设置git获取所有远程分支而不仅仅是主分支。原始配置如下:

$ git config --get remote.origin.fetch
+refs/heads/master:refs/remotes/origin/master

1
如果你不介意我问一下,那么配置如何最初变成 +refs/heads/master:refs/remotes/origin/master 的? - nishantjr
1
好问题。不幸的是,我不知道。我不记得做过任何可能影响该配置的事情。 - Mixopteryx
2
一个让我花了一个下午时间处理的麻烦问题,出现了无尽、晦涩难懂的错误提示,例如“merge: origin/master - not something we can merge”和“merge: origin/master - not something we can merge”。这个解决方案解决了这个问题!我将错误字符串包含在内,以便后来的Git受害者...咳咳...用户可以找到联系,并感谢你和我。 - Dario Fumagalli
3
@Mixopteryx 当我使用 --depth 克隆存储库时,也发生了这种情况;显然,如果你在克隆时使用 --single-branch,也会出现这种情况。 - petrpulc

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