Skip to main content

Command Palette

Search for a command to run...

Git Tip: Deleting merged branches locally

Updated
1 min read
S

I have been in love with computers and everything related since I played my first game of Dangerous Dave back in the 90s.

Graduating with a master's degree in Biology, and a bachelor's in Pharmacy; I have been fortunate enough to dabble my hands in things ranging from copywriting to computer networks.

I love pixel art!

I've written a few more things about me, here and here!

As a part of our spring cleaning drive in our remote repo, we found and deleted a lot of leftover merged branches.

I wanted to find a quick way to do the same locally, and I happened at an answer, which I've written down below, to save it as a quick note for myself, and others.


Add the following to your git config by running the command git config -e --global

[alias]
    cleanup = "!git branch --merged | grep  -v '\\*\\|master\\|development' | xargs -n 1 git branch -d"

Now you can use git cleanup; to delete all the local branches (excluding master and development) which are already merged into the currently checked out branch.

807 views
C

this should also work:

git config --global alias.cleanup "!git branch --merged | grep  -v '\\*\\|master\\|development|develop' | xargs -n 1 git branch -d"

I also added develop branch because that what we mostly call it instead of development

1