git branch | grep -v "master" | xargs git branch -D
// -- Clear all branches except Master Branch --
git branch -D $(git branch | grep -v 'master')
// This will clear all your branches you have on local that you have
// not pushed to your repository. eg: IF, you created a branch that was,
// not pushed it will remain along with amster.
// But the others will be cleaned.
// -- Delete a single branch
git branch -D branch-name
git branch -r | grep 'origin' | grep -v 'master$' | grep -v HEAD | cut -d/ -f2- | while read line; do git push origin :heads/$line; done;
$ git branch -r | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | xargs git branch -d
# Shorthand for deleting localy all branches already deleted on remote
# set this alias in git.config
git config --global alias.gone "! git fetch -p && git for-each-ref --format '%(refname:short) %(upstream:track)' | awk '$2 == "[gone]" {print $1}' | xargs -r git branch -D"
# then run
git gone
$ git branch | grep -v '^*' | xargs git branch -D
git branch -r | grep 'origin' | grep -v 'master$' | grep -v 'develop$' | grep -v HEAD | cut -d/ -f2- | while read line; do git push origin :heads/$line; done;