Delete all local merged branches in git

Its common to use branches in git while fixing bugs or adding new features to your project. However, this also means that over a period of time, you might end up with a lot of local branches that were already merged into your master but for one reason or the other, you didnt delete them at the time of merge.

Instead of manually deleting each merged branch, you can use the following command to delete all the branches that are merged into the current branch while excluding the master and the current branch itself.

git branch --merged | grep -Ev '^(. master|\*)' | xargs -n 1 git branch -d

Ryan Sukale

Ryan is just a regular guy next door trying to manage his life and finances.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *