'git branch -av'显示不再存在的远程分支

这可能是一个愚蠢的问题,但我是全新的混帐,并看到一个远程分支不再存在。

$ git branch -a * master remotes/origin/master remotes/origin/production 

我不相信生产分支是远程存在的,不知道为什么它仍然显示在本地。 我怎样才能删除/删除这个分支? 以下是试图删除它的样子:

 $ git push origin :production error: unable to push to unqualified destination: production The destination refspec neither matches an existing ref on the remote nor begins with refs/, and we are unable to guess a prefix based on the source ref. error: failed to push some refs to 'git@IP:puppet.git' 

我可以检查所谓的远程生产分支,但得到这个:

 $ git checkout origin/production Note: checking out 'origin/production'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b new_branch_name HEAD is now at c323996... added powerdns module, no really 

我不知道我在做什么。 任何帮助,将不胜感激。

你必须做:

 git remote prune origin 

所以有两个问题。 在这两种情况下,记住Git是分布式的。

第一。 当你做这样的事情

$ git branch -a

该操作在您的本地仓库而不是远程计算机上执行。 换句话说,你的本地回购正在报告所有知道的分支。 这些可以是本地分支(如“主”),也可以是从远程获取的远程分支。 自上次获取以来,远程仓库的“生产”分支已经更改,但是您的本地仓库不知道这一点。 manojlds的答案是正确的。 跑

$ git remote prune origin

去除陈旧的分支。

'git push origin:production'命令用于从远程计算机的git repo中删除分支。 不是你当地的回购。 在这种情况下,其他人已经删除了远程计算机的git repo上的分支,因此您会看到此错误消息。

这是一个总结这些命令的链接 。

第二个问题涉及结帐。

在检出分支时,你想从本地分支,而不是远程分支。 这就是为什么你得到一个分离的HEAD的错误。 git-notes回购对这个问题有很好的解释。 基本上这个关键词是

但是,当您签出不合适的本地分支名称时,HEAD不再是对任何事物的符号引用。 相反,它实际上包含了您要切换到的提交的SHA-1哈希(提交ID)。

现在,如何查看本地分支,就像远程分支一样?

很简单,你创build一个本地分支,在结账远程分支的时候。

$ git checkout -b my_local_branch起源/生产

 git remote prune origin 

是正确的,只是添加你可以使用--dry-run选项,报告什么分支将从您的本地回购修剪,但实际上并没有修剪它们

 git remote prune origin --dry-run