Skip to content

Instantly share code, notes, and snippets.

@fmartins-andre
Last active December 20, 2024 13:19
Show Gist options
  • Save fmartins-andre/086d16f0747bc95a17c31d1a27cbf622 to your computer and use it in GitHub Desktop.
Save fmartins-andre/086d16f0747bc95a17c31d1a27cbf622 to your computer and use it in GitHub Desktop.
Remove local branches that were merged
#!/bin/bash
echo 'Removing origins...'
git remote prune origin
BRANCHES=`git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}'`
if [[ `echo -e "$BRANCHES" | wc -w` -gt 0 ]]; then
echo 'Removing branches:'
echo $BRANCHES
echo $BRANCHES | xargs git branch -D
else
echo 'No branches to delete'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment