Git clean old branches

I would like to create a git command that will remove any branches, all of which will be included in the current branch, for example.

$ git branch groups * master $ git cleanup-branches deleted groups # all commits are included in master $ git branch * master 

How can i do this?

+4
source share
1 answer

Here you can use git branch -d since it will not remove any branch that has not yet been merged with your current branch:

 git config --global alias.cleanup-branches \ '!git branch | grep -v "\*" | awk "{ print $1 }" | xargs git branch -d' 

Just tried it locally and it worked, although it's a little scary to watch how it works.

+4
source

All Articles