DEV Community

Discussion on: Delete merged branches using one command

Collapse
andreipavel0 profile image
Andrei Pavel • Edited on

Or as I prefer it, part of .gitconfig:

[alias]
  delete-merged-local-branches = ! git branch --merged master | grep -Ev '(^\\*|master)' | xargs -n 1 git branch -d
  delete-merged-remote-branches = ! git branch -r --merged master | grep -Ev '(^\\*|master)' | cut -d '/' -f2- | xargs -n 1 git push --delete origin
Enter fullscreen mode Exit fullscreen mode

Then:

$ git delete-merged-local-branches
$ git delete-merged-remote-branches
Enter fullscreen mode Exit fullscreen mode

Thanks for sharing!