Skip to content

Instantly share code, notes, and snippets.

@robhurring
Created June 24, 2014 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robhurring/acf1a4491d771838027e to your computer and use it in GitHub Desktop.
Save robhurring/acf1a4491d771838027e to your computer and use it in GitHub Desktop.
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