Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cleans up branches merged into "dev" from your local repo (except current branch, dev, and master)
#!/usr/bin/env sh
# IMPORTANT: exclude the current branch (*), master and dev branch. Add any other patterns here
# and do a --dry-run if you're unsure
to_prune=$(git branch --merged dev | grep -v '\*\|master\|dev')
function show_help {
echo Usage: $(basename $0)
echo " -n [--dry-run] Print branches that would be removed"
}
case "$1" in
-n|--dry-run)
echo "\033[1;37mBranches that would be deleted (locally):\033[0m"
for branch in $to_prune; do
echo " \033[31m$branch\033[0m"
done
;;
-h)
show_help
;;
*)
for branch in $to_prune; do
echo "\033[31m$IBAD $(git branch -d $branch)\033[0m"
done
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.