Bulk deleting local Git branches using Regex
Shadow Smith
Posted on January 15, 2020
If you are reading this, you obviously have a need to bulk delete local Git branches because you are crushing all of your assigned Work Items.
So here's a shortcut to clean up your local environment.
Write your dry run using regex using this command formula:
git branch | grep [regex expression goes here]
So for example, to view all local branches that are prefixed with "feature", you would use the command.
git branch | grep feature*
Once you run that command and triple check that you wish to delete all of the local branches that are returned, run this command to delete them.
git branch | grep feature* | xargs git branch -D
BONUS TIP:
Here's how to delete all local branches except for master.
git branch | grep -v "master" | xargs git branch -D
You're welcome!
💖 💪 🙅 🚩
Shadow Smith
Posted on January 15, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
javascript Streamline Your Workflow: Setting Up Git Hooks with Husky to Simplify Version Updates
April 13, 2024
productivity 6 Repositories recommended by GitHub to Boost Your Programming Productivity
May 2, 2023
tutorial How to Take Your Git Commit Messages to The Next Level With a Commit Template
December 21, 2022