git远程分支已删除但仍出现在'branch -a' [英] git remote branch deleted but still appears in 'branch -a'
问题描述
现在,我决定删除一个名为 coolbranch
的分支。它(远程和本地):
git push来源:coolbranch
git分支-D coolbranch
好极了!
现在该分支真的被删除了。
但是当我运行时
git branch -a
我仍然可以得到:
remotes / origin / coolbranch
要注意的是,当我克隆一个新的存储库时,一切正常,并且 git branch -a
不显示分支。
我想知道 - 有没有办法从分支-a
列表中删除分支,而无需克隆新实例?
git branch -d -r origin / coolbranch
( - r
很容易忘记...)
-r在这种情况下将列出或删除(如果与-d一起使用)远程跟踪分支。根据这里找到的git文档: https://git-scm.com/docs/git-branch
Lets' 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.
But when I run
git branch -a
I still get:
remotes/origin/coolbranch
Something to notice, is that when I clone a new repository, everything is fine and git branch -a
doesn't show the branch.
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
, 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
(The -r
is easy to forget...)
-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屋!