How To Delete All Local Git Branches In One Go

The Road to Next

Sponsored

This is for people who want to climb to a senior level, and those who want to build real-world SaaS products. Master Full-Stack Web Development with Next.js 16 and React 19!

Sometimes, you might want to delete all your local branches from a project. Doing it one by one might be very tedious when you have lots of branches.

Thus, with the command below, you can delete all your local branches except main:

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

Of course, you can replace the main branch with any other branch.


Additionally, you might be interested in Git Aliases. The aliases will improve your experience significantly, and it is going to save you time as well.

The Road to Next

Sponsored

This is for people who want to climb to a senior level, and those who want to build real-world SaaS products. Master Full-Stack Web Development with Next.js 16 and React 19!