Skip to content

Instantly share code, notes, and snippets.

@CristianoPassos
Created September 17, 2018 10:28
Show Gist options
  • Save CristianoPassos/1c374933ca44eba2c2c9fdbf3e8548a7 to your computer and use it in GitHub Desktop.
Save CristianoPassos/1c374933ca44eba2c2c9fdbf3e8548a7 to your computer and use it in GitHub Desktop.
Remove merged Git branches
#!/bin/bash
MAIN=${1:-master}
BRANCHES=$(git branch --merged $MAIN | grep -v -e 'master\|staging\|development\|\*')
git pull
clear
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
git fetch --prune
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment