Remove local branches except master git branch | grep -v '^*' | xargs git branch -D Remove remote branches except master REMOTE='origin' && MASTER='master' && git branch -r | grep '^ ${REMOTE}/' | sed 's|^ ${REMOTE}/|:|' | grep -v '^:HEAD' | grep -v '^:${MASTER}$' | xargs git push ${REMOTE}