如何识别 Git 中已删除的远程分支?

How to identify a deleted remote branch in Git?

如何知道服务器端在Git中删除了一个远程分支?

我和我的同事一起开发了一个 UserStory。我们为它创建了一个分支(比方说 US_123)。完成所有这些工作后,我的同事将 US_123 合并到 master 分支并删除(使用 git push origin --delete US_123)。

对我来说,除了和同事沟通,有什么办法可以知道US_123已经在服务器端被删除了

我已经从服务器获取代码:

  git fetch
  git pull

但是远程分支origin/US_123(和本地跟踪分支US_123')仍然在我这边列出。

git fetch
git pull
git branch -vv
  US_123 9aee544 [origin/US_123] Merge branch 'US_123'
* master 9aee544 [origin/master] Merge branch 'US_123'

预期: 远程分支被标记为已删除。和TFS一样,分支会变成'gray'表示相关的远程分支在TFS中被某人删除了。

实际: 注意到发生了。至少,没有任何信息告诉我 US_123 已在服务器端被删除。

W:\Git_Proj>git branch -vv
  US_123 9aee544 [origin/US_123] Merge branch 'US_123'
* master 9aee544 [origin/master] Merge branch 'US_123'

git有两种常用的方法。

我倾向于使用fetch(这里假设origin

git fetch -p --dry-run

其中 -p 代表 "prune" 并要求 git 使用 fetch

修剪过时的 remote-tracking 分支

而且,正如 Alexan 在他的评论中所提供的那样,您可以这样做

git remote prune origin --dry-run

两者(因为他们使用 --dry-run)将输出分支列表,如果您键入相同的命令但没有 --dry-run 将被 删除