Pre: ensure you are on your main branch (usually master or devel) and that everything is up-to-date with your origin
git checkout master
git fetch
To list all the merged branches, use
git branch -r --merged | grep -v master | grep -v devel
Note the use of grep to esclude merged branches that should be kept (master, devel)
Then we use sed
to remove the origin/
part, and feed each branch name to git push --delete origin [branchname]
.
The resulting command is:
git branch -r --merged | grep -v master | grep -v devel | sed 's/origin\///' | xargs -n 1 git push --delete origin
You can also use this version to delete your local merged branches. Same deal, move to your master branch and use:
git branch --merged | grep -v master | grep -v devel | xargs -n 1 git branch -d
Gist based on this StackOverflow answer: https://stackoverflow.com/a/18143078/2304450 and integrated with the info from the comments