A Git alias for deleting locally merged branches


Create a file, and call it anything. Its content should look like this:

#!/usr/bin/env bash
git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d

Assuming that the above file is called gitclearmerged, then have it be executable:

chmod +x gitclearmerged

In your ~/.gitconfig file, look for a section labeled [alias].

Then, in that section, add the following value:

deletemerged = "!f() { <path to>/gitclearmerged; }; f"

Be sure to replace <path to> with something else!

Save the file, and you should be able to invoke the following commnad:

git deletemerged
Edit this page
Want to make your own site like this? Try gatsby-theme-code-notes by Zander Martineau.
Notes on code. My second brain, by Sal Rahman.