Skip to content

Instantly share code, notes, and snippets.

@mkoryak
Forked from bxt/git-deletebranches.sh
Last active December 6, 2016 19:44
Show Gist options
  • Save mkoryak/d9cac735b0463e4611bc5fdacd88459f to your computer and use it in GitHub Desktop.
Save mkoryak/d9cac735b0463e4611bc5fdacd88459f to your computer and use it in GitHub Desktop.
Git Delete Merged Branches
#!/bin/bash
MAIN=${1:-develop}
BRANCHES=$(git branch --merged $MAIN | grep -v -e 'master\|staging\|develop\|\*')
echo Branches merged into $MAIN:
echo $BRANCHES
read -p "Delete these branches (y/n)? " answer
if [ "$answer" = "n" ]; then echo aborting && exit; fi
echo $BRANCHES | xargs -n 1 git branch -d
@acconrad
Copy link

acconrad commented Dec 6, 2016

👍

@TallGirlVanessa
Copy link

I use something similar:

alias gmgd="git branch -a --merged | sed 's/^[* ] //' | awk '{print \$1}' | xargs git show -s --pretty=format:'%an %d %cr' | sort | grep -v HEAD"
alias gcln="git branch --merged | grep -v -e 'master' -e 'develop' -e 'release-candidate' -e '*' | xargs git branch -d"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment