A simple prune will not delete the local branch.
Here is another approach to achieve a real deletion. Be sure to execute "git fetch -p" first to get the latest status of the remote repositories.
git branch -vv | grep ': gone]'| grep -v "\*" | awk '{ print $1; }' | xargs -r git branch -d
This will check all local branches and their origin and will delete all local branches whose origin was deleted.
In detail:
git branch -vv
will list your local branches and show information about the remote branch, saying “gone” if it is not present anymore.
grep ': gone]'
will fetch the branches that match the “ gone]” phrase.
grep -v "\*"
will fetch only lines that do not contain an asterisk. This will ignore the branch you are currently on and also prevent that the “git branch -d” is executed with a “*” at the end which would result in deleting all your local branches
awk '{print $1}'
will fetch the output until the first white space, which will result in the local branch name.
xargs git branch -d
will use the output (branch name) and append it to the “git branch -d” command to finally delete the branch. If you also want to delete branches that are not fully merged, you can use a capital “D” instead of “d” to force delete.