git delete all local branches except one code example Example: git delete all branches except master git branch | grep -v "master" | xargs git branch -D