git branch --merged | grep -v "*" | grep -v master | xargs -n 1 git branch -d
This assumes you have all branches checked out. "git branch -r --merged" will give you all remote branches that are merged in to whatever your current branch is. Also, depending on your branching strategy and how you deal with bugs or hotfixes, you may want to filter on how long it's been since the branch was touched.
Why the "grep -v dev"?
Thanks for the answer @adevore3.
So, I just removed the grep -v dev. There is no nonse at all. Sorry about that.
About the previously question.
I always run this command on master branch.
About the bugs and hotfixes branches, I just merge it when it's fully tested.
I mean, I run this command always to remove branches I forgot to.