从Git中删除旧的远程分支 [英] Remove old remote branches from Git
问题描述
当我在Git中使用bash autocompletion时,它不断向我展示我不再拥有的旧遥控器的分支。当我做一个 git branch -la
时,它会显示那些旧的远程和分支,而 git分支-l
不会。一个 ls .git / refs / remotes /
也会显示它们。但是,它们并不存在于我的 .git / config 中,当我运行 git remote show
时,它们都不显示。
那么我该如何摆脱它们呢,因为我的自动完成列表现在太长了。
我已经试过了:
git reflog expire --expire = now - all
git gc --prune = now
rm .git / refs / remotes / theoldremote
git remote prune theoldremote
我也意识到我可以重新克隆回购,但这只是作弊; - )
此外,在V2.0.1之前,当您从git配置中移除远程设备时,远程追踪分支在某些情况下不会被删除(请参阅VonC的答案)。
删除过时的远程 - 为您的远程存储库之一追踪分支(在远程存储库中删除的分支),运行
git remote prune<远程>
引用手册页或 git remote
:
$ b
修剪
删除< name>下的所有陈旧跟踪分支。这些陈旧的分支已从$ lt; name> ;,
引用的远程存储库中移除
,但仍在远程/<名称>中本地可用。
使用--dry-run选项,报告将修剪哪些分支,但
不会实际修剪它们。
然而,从你的问题看来,你似乎手动删除了 .git / refs / remotes / theoldremote
,所以Git不再了解远程存储库,跟踪分支属于。这不是你应该怎么做的。
删除远程仓库的正常方法是运行
git remote rm< remote>
这将从您的 如果您只是删除 您需要选项 When I use bash autocompletion in Git, it keeps showing me branches of old remotes that I don't have anymore. When I do a So how do I get rid of them because my autocomplete list is too long right now. I have already tried: I'm also aware of the fact that I can just re-clone the repo but that's just cheating ;-) Git does not delete the (local) remote-tracking branches automatically if the branch was deleted in the remote repository. Additionally, before V2.0.1 remote-tracking branches were in some cases not deleted when you removed the remote from your git config (see VonC's answer). To delete stale remote-tracking branches (branches that were deleted in the remote repository) for one of your remote repositories, run To cite the man page or prune Deletes all stale 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. However, from your question it seems you manually removed The normal way to remove a remote repository is to run This will remove the remote from your If you just delete the directory under You need option 这篇关于从Git中删除旧的远程分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! .git / config $ c
.git / refs / remotes / 下的目录,则会删除远程跟踪分支。 code>,分支机构将保持在后面。然后您需要手动删除它们:
git branch -rd< remote> /< branchname>
-r
来删除远程分支。git branch -la
it shows those old remotes and branches while a git branch -l
won't. A ls .git/refs/remotes/
also shows them. However, they are not present in my .git/config and neither are they shown when I run git remote show
.git reflog expire --expire=now --all
git gc --prune=now
rm .git/refs/remotes/theoldremote
git remote prune theoldremote
git remote prune <remote>
git remote
:
.git/refs/remotes/theoldremote
, so Git no longer knows about the remote repository that the remote-tracking branches belonged to. That's not how you're supposed to do it.git remote rm <remote>
.git/config
, and will delete the remote-tracking branches..git/refs/remotes/
, the branches will remain behind. Then you will need to remove them manually: git branch -rd <remote>/<branchname>
-r
to delete a remote branch.