显示不再存在的远程分支

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

$ 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

我完全不知道自己在做什么,如果你能帮忙我会很感激的。

28742 次浏览

你必须:

git remote prune origin

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

首先,当你做一些

$Git Branch-a

操作是在您的本地回购而不是远程计算机上执行的。换句话说,您的本地回购正在报告所有已知的分支机构。这些分支可以是本地分支(比如“ master”) ,也可以是远程 取来的的远程分支。自从上次获取以来,远程回购的“生产”分支已经发生了变化,但是您的本地回购并不知道这一点。来自 Manojld的答案是正确的。快跑

$git Remote prune source

去除不新鲜的树枝。

使用“ git push source: production”命令从远程计算机的 git repo 中删除分支。不是当地的回收站。在这种情况下,其他人已经删除了远程计算机的 git repo 上的分支,所以您可以看到这个错误消息。

下面是一个 链接,它总结了这些命令。

第二个问题处理结帐。

签出分支时,您希望从 本地分支而不是远程分支进行签出。这就是为什么会出现关于分离的 HEAD 的错误。在 Git-note 回购有一个很好的解释血淋淋的细节问题。基本上关键词是

但是,当您签出任何不正确的本地分支名称时,HEAD 就不再是对任何东西的符号引用。相反,它实际上包含要切换到的提交的 SHA-1散列(提交 ID)。

现在,如何检出与远程分支相同的本地分支?

简单,在签出远程分支时创建本地分支。

$git checkout-b my _ local _ Branch source/production

git remote prune origin

是正确的,只需添加您可以使用 --dry-run选项,报告哪些分支将被删除从您的本地回购,但实际上不删除它们

git remote prune origin --dry-run