Delete all local merged branches in git

Its com­mon to use branches in git while fix­ing bugs or adding new fea­tures to your project. How­ever, 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 mas­ter but for one rea­son or the other, you didnt delete them at the time of merge.

Instead of man­u­ally delet­ing each merged branch, you can use the fol­low­ing com­mand to delete all the branches that are merged into the cur­rent branch while exclud­ing the mas­ter and the cur­rent 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 *