陈旧的远程分支不会从上游引用中清除

stale remote branches are not cleaned from upstream references

在 git 存储库中调用 meld 时,在打开 meld 之前收到一堆警告:

# from within a git repo :
$ meld .
fatal: bad revision '^origin/branch/one'
fatal: bad revision '^origin/branch/two'
fatal: bad revision '^origin/branch/three'
...

这只是打印在 STDERR 上的警告,meld 之后运行正常并显示预期的差异。

这些分支中的大多数都有本地结帐,但在 origin 上没有匹配的远程引用。
这些引用之一甚至在本地不存在(它与现有分支的拼写错误)。

有人知道我可以处理这些可耻的消息吗?

问题出在我的回购配置中。

一些本地分支机构仍在跟踪陈旧的远程分支机构:
.git/config 文件仍然包含以下部分:

[branch "branch/one"]
    remote = origin
    merge = refs/heads/branch/one

即使远程分支 branch/one 不再存在,并且我的本地引用 origin/branch/one 已(正确)删除。

我没有找到任何直接命令来清理我的本地分支。
我希望 git remote prune origin 能解决这个问题,但没有。

这是我发现让我的本地分支停止跟踪陈旧的远程分支的方法:

# enumerate all local branches, and print "branchname upstreamname" :
git for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads |\

# keep branches which track a remotre branch in origin :
grep "origin/" |\

# loop on output :
while read local remote; do
  # use any command which fails on an invalid ref :
  git show $remote -- > /dev/null
  # if it failed : stop tracking this stale remote
  if [ $? != 0 ]; then
    git branch $local --unset-upstream
  fi
done