Cleanup merged branches for local Git by aliase

 While working with Git locally we day by day: create new feature branches, commit, create PR's, merge them, and finally repeat the process.

So do I ;) and one day I required to view some of my old branches and use:

git branch -a

And of course, I received an endless list of my branches for all the times...

As we are all lazy, I decided to search for an easy solution to clean all merged to master branches and  solution is quite simple by using command:

 git branch --merged | grep -v '\\* master' | xargs -n 1 git branch -d ;

(thanks for this solution https://stevenharman.net/git-clean-delete-already-merged-branches) 

But type this command every time, even if not often, or save it in notepad for better time sounds not cool.

So I decided to use Git Aliases for this (if you are not familiar with git aliases feel free to google it, rather useful option).

For adding new alias you could add it into .gitconfig file (it is a default file created with installing git and available under Users/user directory).

What we need to add is just one line:

"!func() { git branch --merged | grep -v '\\* master' | xargs -n 1 git branch -d ; }; func"

This is an example of how the final file will look like (on a Windows machine):

gitconfig alias example

 And now, after saving, you are able to run $ git cleanup