我怎么告诉Git警告我可能删除的远程分支

时间:2010-01-20 00:23:40

标签: git

想象一下,我有一个我从某个来源克隆的本地存储库。在我的初始克隆时,原点有四个分支: featureA,featureB,featureC master 。如果我将更改推送到删除 featureA 分支的原点,我希望在下次发布时看到有关它被删除的内容:

  

$ git pull origin

然而,发生的事情是我没有看到任何内容,当我尝试用

拉下特定分支时
  

$ git pull origin featureA

我收到以下错误:

  

致命:无法找到远程参考功能A
  致命的:远程端挂了   出乎意料

这完全有道理,因为分支实际上是从遥控器中删除所以是的,参考不再存在,但是我想知道为什么我没有得到关于这个事实的通知。我的远程 .git / config 如下所示:

  

[遥远的“原产地”]
  fetch = + refs / heads / :refs / remotes / origin /
  url = cjames@svn.perecep.com:/data/git/perecep.git

我编写了一个小shell脚本,它使用 git ls-remote 以及 git branch -r 的输出来检测其分支不再存在的远程引用在服务器上,如果我想删除它们,请提示我,但我想知道我是否只是在做一些内在错误的事情?

2 个答案:

答案 0 :(得分:3)

好的,不需要特殊的脚本。我想我忽略了这个命令

  

$ git remote prune origin

从手册页:

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

           With --dry-run option, report what branches will be pruned, but do 
           no(sic) actually prune them.

答案 1 :(得分:2)

我认为你做错了什么。您的本地分支不依赖于远程分支存在,并且当您的本地分支(具有相同名称且表面上相同的历史记录)继续存在时,远程分支被删除是完全有效的事务状态。这是你所描述的“集中式”方法,如果有的话,在Git中被认为是非正统的。

编辑:从切面来看,您可能对git-branch的--track--no-track选项以及branch.autosetupmerge配置变量感兴趣。