🚧 Hey there! The site is under construction. I'm actively working to have all basic features working properly.

How to delete multiple git branchs at once

Sometimes you forgot to delete you local branchs, which happens to me all the time, and someday you type git branch to see you local branchs and you ended up with a huge list. So the best way would be deleting multiple branchs at the same time to save up some time writing each branch name one by one.

TLDR;

You can delete multiple branchs by typing each name separated by spaces:

git branch -D branch1 branch2 branch2

Or if the branchs you want to delete has a shared name pattern you can use the code bellow to delete multiple branchs at the same time:

git branch -D `git branch --list 'prefix*'`

Example

Deleting multiple branch with the same prefix:

# List your branchs
git branch

# Local branchs
main*
prefix-branch1
prefix-branch2
prefix-branch3

# delete all branchs with the 'prefix-' in their names
git branch -D `git branch --list 'prefix-*'`

# Check the list again
git branch

# Branchs deleted
main*

This works with any kind of pre or posfix too.