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

问题描述:

这可能是一个愚蠢的问题,但我是全新的git,并且看到一个不再存在的远程分支。'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 '[email protected]: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 

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

+0

'git fetch'后git branch -a的输出是什么? – alediaferia 2012-01-07 01:20:27

+2

仍然相同。 – CarpeNoctem 2012-01-07 01:47:33

+0

可能重复[如何强制删除GitHub中的远程分支?](http://*.com/questions/8754183/how-to-forcefully-delete-remote-branch-in-github) – Cascabel 2012-01-07 02:03:31

你要做的:

git remote prune origin 
+4

谢谢你的工作!你能详细说明幕后发生了什么吗? – CarpeNoctem 2012-01-07 01:46:47

+7

这些是您本地仓库的远程追踪分支,如果分支在远程仓库中被删除,您必须清除它们。 – manojlds 2012-01-07 01:47:46

+0

你做了我的一天。 – 2017-02-06 21:32:00

因此,有两个问题。在这两种情况下,请记住Git是分发的。

第一。当你不喜欢的东西-a

在您的本地回购不是远程计算机执行的操作

$ git的分支。换句话说,你的本地回购是报告所有知道的分支。这些可能是本地分支(如'主')或远程分支,它从远程获取。自上次获取以来,远程仓库的“生产”分支已发生变化,但您的本地仓库并不知道这一点。 manojlds的答案是正确的。运行

$ git的远程修剪起源

删除陈旧的分支机构。

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

这里是总结这些命令的link

第二个问题涉及结帐。

检出分支时,您希望从本地分支,而不是远程分支。这就是为什么你会得到关于分离HEAD的错误。这个git-notes repo对这个问题有很好的解释。基本上,关键短语是

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

现在,如何签出一个本地分支,就像远程分支一样?

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

$ git的结帐-b my_local_branch产地/生产

git remote prune origin 

是正确的,只是增加你可以使用--dry-run选项,报告的是分支将从本地回购被修剪,但实际上犯规修剪它们

git remote prune origin --dry-run