简体   繁体   English

如何删除除master之外的所有本地分支并在一个没有别名的命令中开发?

[英]How to delete all local branches except master and develop in one command without aliases?

When working on projects with Git Flow or similar workflow where more than one stable branch exists I create a lot of feature branches ( feature/do-something-1 , hotfix/fix-bug-1 , etc.).在使用 Git Flow 或存在多个稳定分支的类似工作流处理项目时,我创建了许多功能分支( feature/do-something-1hotfix/fix-bug-1等)。

Sometimes I need to clear the list of local branches because it is literally impossible to manage them with dozens of rudimentary branches.有时我需要清除本地分支的列表,因为用几十个基本分支来管理它们实际上是不可能的。 I usually delete them one at a time by copying and pasting the branch names into the git branch -d command.我通常通过将分支名称复制并粘贴到git branch -d命令中来一次删除它们。 But it takes so long that it's easier to delete the entire repository and clone again.但是这需要很长时间,以至于删除整个存储库并再次克隆会更容易。

I want to delete all of them except master and develop in one command (without writing additional shell script/aliases), but all solutions I've found on the internet only allow you to delete everything except one branch ( master , for example).我想删除除master之外的所有这些并在一个命令中develop (无需编写额外的 shell 脚本/别名),但我在互联网上找到的所有解决方案都只允许您删除除一个分支之外的所有内容(例如master )。 This is not an appropriate solution.这不是一个合适的解决方案。 Has anyone faced a similar problem?有没有人遇到过类似的问题?

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

Here is a simpler variant of same answer:这是相同答案的更简单变体:

git branch -D $(git branch | grep -v -e "master$" -e "develop$")

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM