git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d
- git branch –merged : first, you are simply listing all the branches currently merged with your current checked out branch;
- egrep -v “(^*|master|dev)” : you are using the invert matching feature of grep in order to exclude any branches that may be called “master” or “dev”, just in case;
- xargs git branch -d : you are deleting every single branch listed before.