git远程分支已删除但仍出现在'branch -a' [英] git remote branch deleted but still appears in 'branch -a'

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

问题描述



现在,我决定删除一个名为 coolbranch 的分支。它(远程和本地):

  git push来源:coolbranch 
git分支-D coolbranch

好极了!
现在该分支真的被删除了。



但是当我运行时

  git branch -a 

我仍然可以得到:

  remotes / origin / coolbranch 

要注意的是,当我克隆一个新的存储库时,一切正常,并且 git branch -a 不显示分支。



我想知道 - 有没有办法从分支-a 列表中删除分支,而无需克隆新实例?

$ b $如另一个答案中所建议的那样,git remote prune origin 会删除所有这样的陈旧分支。这可能是大多数情况下你想要的,但是如果你想删除那个特定的远程追踪分支,你应该这样做:

  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屋!

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