--- title: Delete merged branches tags: repository,branch,advanced firstSeen: 2021-04-08T19:42:01+03:00 lastUpdated: 2021-04-13T21:10:59+03:00 --- Deletes all local merged branches. - Use `git branch --merged ` to list all branches merged into ``. - Use the pipe operator (`|`) to pipe the output and `grep -v "(^\*|)"` to exclude the current and the target ``. - Use the pipe operator (`|`) to pipe the output and `xargs git branch -d` to delete all of the found branches. ```shell git branch --merged | grep -v "(^\*|)" | xargs git branch -d ``` ```shell git checkout master git branch # master # patch-1 # patch-2 # Assuming `patch-1` is merged into master git branch --merged master | grep -v "(^\*|master)" | xargs git branch -d git branch # master # patch-2 ```