DEV Community

Rich Field
Rich Field

Posted on • Edited on

How to delete multiple branches in Git

I've been a wee bit lazy keeping my local branches up to date.
Thankfully, I learnt today that it's super easy to delete multiple branches at a time.

First run this command to test what branches will be deleted.

> git branch | grep "<pattern>"

Then run this to actually do the delete

> git branch | grep "<pattern>" | xargs git branch -D

E.g.
> git branch | grep "ch100-*"
> git branch | grep "ch100-*" | xargs git branch -D

Top comments (0)