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