简体   繁体   中英

GIT: How to delete all Hotfix and Feature branches, and keep Development, Releases and Master - automatically?

As a way to organize my repositories, I would like to know how to run either a command or script to delete all Hotfix and Feature branches only. I intend to do this once they are not useful anymore. These branches will sometimes be used on both local and remote.

For the safety of the branches in your repo, please read the entire answer.

I'm going to assume that all your feature or hotfix branches have feature or hotfix in the name. The command to delete all of them would be the following

git branch -D `git branch | grep -E '(hotfix|feature)'`

HOWEVER, before you run that, run

git branch | grep -E '(hotfix|feature)'

This command will tell you exactly which branches are going to be deleted. Only after you are satisfied with the output of this, should you run the first command above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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