how to delete all branches in git except master

Shell
git branch | grep -v "master" | xargs git branch -D$ git branch | grep -v "master" | xargs git branch -D $ git branch | grep -v '^*' | xargs git branch -D
Source

Also in Shell: