[Git] Command to delete all merged local branches

Tadashi Shigeoka ·  Tue, March 5, 2019

Here’s a command to delete all local branches that have been merged into the master branch in git.

Git

Command to delete all merged local branches

Here’s the shell script to delete all local branches that have been merged into the master branch:

git branch --merged | \
grep -vE '^\*|master$|develop$' | \
xargs -I % git branch -d %

Since running the above command every time is troublesome, I recommend adding it as an alias in .gitconfig as follows:

~/.gitconfig

[alias]
  delete-merged-branches = !git branch --merged | grep -vE '^\*|master$|develop$' | xargs -I % git branch -d %

That’s all from the Gemba.

References