First of all, you must to be updated with your remote.
After that, the command is:
git branch --merged | grep -v "\*" | grep -v master | grep -v dev | xargs -n 1 -I {} git branch -d {}Explanation:
git branch --merged: list only branches merged intoHEADof current branchgrep -v "\*": remove the current branch from the list (we do not/can not remove it)grep -v master: removemasterbranch from the listgrep -v dev: removedev*branch from the list (useful if you are working with GitFlow ordevelopbranch)xargs -n 1 -I {} git branch -d {}: we will remove branch per branch (because we set the-nto1).
If you want to list all branches that this command will delete, remove the last part:
git branch --merged | grep -v "\*" | grep -v master | grep -v devOriginally created in @artefactop 's Gist