This is not possible in git.
Git's first class principle is to avoid deleting data by accident.
If you push your local branch and someone else (a co-maintainer) may delete it (by accident), you would have lost your entire work if you run the git remote prune
cmd the next time (although you may recover your work via the git's reflog for a short time - but that's another story).
There is no automatic cleanup for local branches. You can observer similar behavior if you merge branch A into brach B. Branch A is still there - even after becoming obsolete - and YOU still have to delete it manually (again - on purpose).
Now that said, you can try something like this (pls, don't blindly copy'n'paste this snippet in your cmd line!)
git branch --merged | xargs git branch -d 2>/dev/null
This will delete literally all merged branches.
Now it's very important to understand merged is a relative term. Merged means any tip of a local branch, that is a child of that branch you're running this command from.
If you run this from your master branch, you will get probably what you want - all obsolete/merged branches (from the perspective of the master branch) will be deleted - even a branch that might be called develop
.
However, if you run this from a different branch... well don't blame me for having any previously merged branches deleted.
PS: you can run git fetch -p
or git fetch --prune
. This will delete all stale remote branches.
If you don't want to add the flags all the time, you can put
[fetch]
prune = true
into your ~/.gitconfig