git Git远程分支已删除,但它仍然出现在'branch -a'中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5094293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git remote branch deleted, but still it appears in 'branch -a'
提问by yonix
Let's say I had a branch named coolbranch
in my repository.
假设coolbranch
我的存储库中有一个名为的分支。
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.
需要注意的是,当我克隆一个新存储库时,一切都很好并且git branch -a
不显示分支。
I want to know - is there a way to delete the branch from the branch -a
list without cloning a new instance?
我想知道 - 有没有办法从branch -a
列表中删除分支而不克隆新实例?
回答by Mark Longair
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 remote prune origin
,正如另一个答案中所建议的那样,将删除所有这些陈旧的分支。在大多数情况下,这可能是您想要的,但如果您只想删除该特定的远程跟踪分支,您应该这样做:
git branch -d -r origin/coolbranch
(The -r
is easy to forget...)
(这个-r
很容易忘记...)
-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
-r
在这种情况下,将“列出或删除(如果与 一起使用-d
)远程跟踪分支”。根据此处找到的 Git 文档:https: //git-scm.com/docs/git-branch
回答by Brian Phillips
Try:
尝试:
git remote prune origin
From the Git remote documentation:
从Git 远程文档:
prune
修剪
Deletes all stale remote-tracking branches under <name>. These stale branches have already been removed from the remote repository referenced by <name>, but are still locally available in "remotes/<name>".
With --dry-run option, report what branches will be pruned, but do not actually prune them.
删除 <name> 下所有陈旧的远程跟踪分支。这些陈旧的分支已经从 <name> 引用的远程存储库中删除,但在“remotes/<name>”中仍然可以在本地使用。
使用 --dry-run 选项,报告将修剪哪些分支,但实际上并不修剪它们。
回答by orip
Don't forget the awesome
不要忘记很棒的
git fetch -p
which fetches and prunes all origins.
它获取并修剪所有来源。
回答by Shadowvail
In our particular case, we use Stash as our remote Git repository. We tried all the previous answers and nothing was working. We ended up having to do the following:
在我们的特殊情况下,我们使用 Stash 作为我们的远程 Git 存储库。我们尝试了所有以前的答案,但没有任何效果。我们最终不得不执行以下操作:
git branch –D branch-name (delete from local)
git push origin :branch-name (delete from remote)
Then when users went to pull changes, they needed to do the following:
然后当用户去拉取更改时,他们需要执行以下操作:
git fetch -p
回答by likaiguo.happy
Use:
用:
git remote prune <remote>
Where <remote>
is a remote source name like originor upstream.
<remote>
远程源名称(如origin或upstream )在哪里。
Example: git remote prune origin
例子: git remote prune origin