使用`git branch -r`命令无法显示远程git分支?

18

我在本地机器上有两个目录,指向同一个远程 Git 仓库。当我在其中一个目录中输入命令 git branch -r 时,我会得到比另一个目录更长的远程分支列表。这是怎么可能的?
似乎在一个目录中会“隐藏”一些远程分支,并在另一个目录中可见。


在一个目录中隐藏和在另一个目录中可见是什么意思? - Andreas Rehm
3个回答

32
我遇到了同样的问题,无法在本地目录中获取远程分支。 git branch -r 显示的分支较少,也不包括最新的更改,而在另一个目录中一切都正常更新。
为解决此问题,我在两个目录上运行了 git config -l 命令,发现缺少了 remote.origin.fetch 设置。运行以下命令解决了我的问题:
git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
git fetch 

From github.com:username/test2
   2bd5e5e..2619d39  master     -> origin/master
 * [new branch]      remotebr2  -> origin/remotebr2
 * [new branch]      remotebranch -> origin/remotebranch

这解决了我在通过Aptana3创建我的repo时遇到的问题。 - Devin Dixon

10

我认为你应该进行获取和修剪操作:

prune 
Deletes all stale tracking branches under <name>. These stale branches have already been removed from the remote repository referenced by <name>, but are still locally available in "remotes/<name>". 

With --dry-run option, report what branches will be pruned, but do not actually prune them.

使用以下命令行:

git fetch
git remote prune origin

2

这两个代码库是否都是最新的?尝试运行 git fetch 命令看看能否解决问题。


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