Skip to content

Instantly share code, notes, and snippets.

@chhibber
Created July 28, 2017 15:51
Show Gist options
  • Save chhibber/13e7ca28fe4e756246764c10e020c661 to your computer and use it in GitHub Desktop.
Save chhibber/13e7ca28fe4e756246764c10e020c661 to your computer and use it in GitHub Desktop.
Prune Merged Branches
  1. Prune branches
  2. Get all branches that have been merged into master
  3. Remove master from the list (grep is for an exact match anchoring with ^ and $
  4. Feed the list of merged branches to xargs and delete them (lower case -d will only delete merged branches)
git fetch -p && git branch --merged master | grep -v '^ *master$' | xargs git branch -d

alias delete-merged-branches="git fetch -p && git branch --merged master | grep -v '^ *master$' | xargs git branch -d"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment