Files
30-seconds-of-code/snippets/git/s/delete-merged-branches.md
2023-05-07 16:07:29 +03:00

827 B

title, type, language, tags, cover, dateModified
title type language tags cover dateModified
Delete merged branches snippet git
repository
branch
duck-plants 2021-04-13T21:10:59+03:00

Deletes all local merged branches.

  • Use git branch --merged <branch> to list all branches merged into <branch>.
  • Use the pipe operator (|) to pipe the output and grep -v "(^\*|<branch>)" to exclude the current and the target <branch>.
  • Use the pipe operator (|) to pipe the output and xargs git branch -d to delete all of the found branches.
git branch --merged <branch> | grep -v "(^\*|<branch>)" | xargs git branch -d
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