git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d
Here is what the above code is Doing:
1. git branch –merged lists the branches that have been merged into the current branch.
2. egrep -v “(^\*|master|dev)” filters out the active branch (asterisk), master, and dev.
3. xargs git branch -d deletes the remaining branches.