Skip to content

Instantly share code, notes, and snippets.

@motia
Created February 12, 2020 13:08
Show Gist options
  • Save motia/02dd8a1a6012d21e5b7aec9d3d5b496b to your computer and use it in GitHub Desktop.
Save motia/02dd8a1a6012d21e5b7aec9d3d5b496b to your computer and use it in GitHub Desktop.
Remove branches merged into the current branch
function remove-merged-branches () {
currentBranch=$(git rev-parse --abbrev-ref HEAD)
read -p "Delete branches merges into $currentBranch y/N? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
git branch --merged | grep -v $currentBranch | while read i; do git branch -d $i; done;
echo "Branches removed successfully"
else
echo "Operation canceled"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment