Remove local branches except the master branch
###########
# DRY-RUN #
###########
# make sure you are on develop; one cannot ever delete the current branch
$ git checkout develop
# get references
$ git fetch
# fast forward (not merge) the current branch
$ git pull origin HEAD
# list every local branch (except 'develop' & 'master') that has already been merged with the local develop
$ git branch --merged develop | grep -vE 'develop|master'
# list stale references (like branches, tags, unreachable commits, etc)
$ git remote prune origin --dry-run
###########
# EXECUTE #
###########
# make sure you are on develop; one cannot ever delete the current branch
$ git checkout develop
# get references
$ git fetch
# fast forward (not merge) the current branch
$ git pull origin HEAD
# delete every local branch (except 'develop' & 'master') that has already been merged with the local develop
$ git branch --merged develop | grep -vE 'develop|master' | xargs git branch -d
# delete all stale tracking branches.
$ git gc --prune=now
# de-reference stale references (like branches, tags, unreachable commits, etc)
$ git remote prune origin