1
0
mirror of https://github.com/danbee/dotfiles-local synced 2025-03-04 08:49:07 +00:00
dotfiles-local/bin/git-sweep

31 lines
632 B
Bash
Executable File

#!/bin/bash
git checkout master
git fetch
git remote prune origin
git branch --merged master | grep -v 'master$' | xargs git branch -d
REMOVABLE=$(git branch -r --merged master \
| sed 's/ *origin\///' \
| grep -v 'master$' \
| grep -v 'production$' \
| grep -v 'staging$' \
| grep -v '^release' \
| grep -v 'next$'
)
if [[ -z "$REMOVABLE" ]]; then
exit 0
fi
echo "The following remote branches are fully merged and will be removed:"
for branch in $REMOVABLE; do
echo "$branch"
done
read -p "Continue (y/n)? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "$REMOVABLE" | xargs git push origin --delete
fi