简体   繁体   English

Git:如何删除所有本地分支(合并与否),除了master和develop

[英]Git : How to delete all local branches (merged or not), except master and develop

I want to clean my local branches (merged or not), except master and develop .我想清理我的本地分支(合并与否),除了masterdevelop

I did some cleanup on the remote repository and I want to have the same locally.我对远程存储库进行了一些清理,我想在本地进行相同的清理。

I tried git fetch --prune which removed some, but there is still a large amount (over a hundred...).我试过git fetch --prune删除了一些,但仍有大量(超过一百......)。

I'm not aware of a way to do this in git out of the box, but this can done with some shell scripting:我不知道在开箱即用的 git 中执行此操作的方法,但这可以通过一些 shell 脚本来完成:

git branch | grep -v master | grep -v develop | xargs git branch -D

Just make sure you are checked out to master or develop before you start, or this script will also attempt to drop the branch you're currently checked out to (and fail to do so, of course).只需确保您在develop之前已签出master或 development,否则此脚本还将尝试删除您当前签出到的分支(当然不会这样做)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何删除除master之外的所有本地分支并在一个没有别名的命令中开发? - How to delete all local branches except master and develop in one command without aliases? 如何使用 PowerShell 删除 Git 中所有合并的本地分支 - How to delete all merged local branches in Git with PowerShell 如何删除除master之外的所有Git远程分支? - How to delete all Git remote branches except master? 如何清除(删除)所有合并的本地分支? - How to clear (delete) all merged local branches? 如何删除所有本地分支,如果合并为主分支将导致无变化? - How can I delete all local branches which would result in no changes if merged into master? 如何删除在 git 中以编程方式合并到 master 的超过 1 个月的分支? - How to delete branches older than 1 month that was merged to master programmatically in git? Git:如何找到所有从未合并回master的分支 - Git: How to find all branches that were never merged back into master 如果看起来不错,我如何列出合并到master的git分支并删除这些分支? - How can i list the git branches which are merged to master and delete the branches if it looks good? git - 如果没有其他分支,如何删除本地 master - git - how to delete local master if you have no other branches 删除所有本地 git 分支 - Delete all local git branches
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM