DEV Community

Discussion on: Command Line Snippets do you keep handy?

ben profile image
Ben Halpern

Remove all local branches except master...

git branch | grep -v "master" | xargs git branch -D
jrohatiner profile image
Judith Author

OMG yes! very important to have handy :)

skkeeper profile image
Fábio André Damas

Inspired by yours but adapted for my use case: delete all branches that are already merged into the current branch safely (doesn't delete branches that aren't fully merged and shows warning):

git branch --merged | grep -v "$(git rev-parse --abbrev-ref HEAD)" | xargs git branch -d 

I use this on develop to delete old feature and bugfix branches.

waylonwalker profile image
Waylon Walker

Nice one!