Sometimes after working on too many features and bug fixes, you endup having too many local branches. In order to remove local branches and to ignore master branch, run following-

git branch | grep -v "master" | xargs git branch -D

Explanation

Here git branch can be used to list, create, or delete branches. If there are no non-option arguments, existing branches are listed; the current branch will be highlighted with an asterisk.

Further we have used pipe | which is used to pass output of previous command to the next command as input. In the above case the grep command will run on the list of branches returned from git branch. The grep utility searches any given input files, selecting lines that match one or more patterns. With option -v, it selects lines are those not matching any of the specified patterns.

Next xargs utility reads space, tab, newline and end-of-file delimited strings from the standard input and executes utility with the strings as arguments. In above case, it will run git branch -D on each branches returned after grep command has filtered the master branch.