#TIL 5 - Delete all local branches except master

Aug 28, 2020 · Dung Huynh

What

Delete all local branches except the current branch (master/main).

Why

Local branches accumulate over time. Clean up to reduce clutter and confusion.

How

git branch | grep -v "master" | xargs git branch -D

For main branch:

git branch | grep -v "main" | xargs git branch -D