Git远程分支已删除,但仍显示在"branch -a"中 [英] Git remote branch deleted, but still it appears in 'branch -a'

查看:127
本文介绍了Git远程分支已删除,但仍显示在"branch -a"中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的存储库中有一个名为coolbranch的分支.

Let's say I had a branch named coolbranch in my repository.

现在,我决定使用以下方法(远程和本地)将其删除:

Now, I decided to delete it (both remotely and locally) with:

git push origin :coolbranch
git branch -D coolbranch

太好了! 现在,该分支确实已删除.

Great! Now the branch is really deleted.

但是当我跑步时

git branch -a

我仍然得到:

remotes/origin/coolbranch

需要注意的是,当我克隆一个新的存储库时,一切都很好,并且git branch -a没有显示分支.

Something to notice, is that when I clone a new repository, everything is fine and git branch -a doesn't show the branch.

我想知道-是否可以在不克隆新实例的情况下从branch -a列表中删除分支?

I want to know - is there a way to delete the branch from the branch -a list without cloning a new instance?

推荐答案

git remote prune origin将删除所有这些陈旧的分支.在大多数情况下,这可能就是您想要的,但是如果您只想删除该特定的远程跟踪分支,则应该执行以下操作:

git remote prune origin, as suggested in the other answer, will remove all such stale branches. That's probably what you'd want in most cases, but if you want to just remove that particular remote-tracking branch, you should do:

git branch -d -r origin/coolbranch

(-r很容易忘记...)

-r将列出或删除(如果与-d一起使用的)远程跟踪分支."根据此处找到的Git文档: https://git-scm.com/docs/git-branch

-r in this case will "List or delete (if used with -d) the remote-tracking branches." according to the Git documentation found here: https://git-scm.com/docs/git-branch

这篇关于Git远程分支已删除,但仍显示在"branch -a"中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆