Delete already merged branches

2019-08-28

The code example below shows how to delete all branches which have already been merged into the current branch:

$ git branch
  feature-1
  feature-2
  feature-3
* master

$ git branch --merged
  feature-1
* master

$ git branch --merged | egrep -v "(^\*|master)"
  feature-1

$ git branch --merged | egrep -v "(^\*|master)" | xargs git branch -d
Deleted branch feature-1 (was 1d7fd54).

Check out this great Stack Overflow answer for more information.


Loading comments...