1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
# ! /usr/bin/env bash
#
# Adapted from http://devblog.springest.com/a-script-to-remove-old-git-branches
#
# This has to be run from master
git checkout master
# Update our list of remotes
git fetch
git remote prune origin
# # Remove local fully merged branches
# git branch --merged master | grep -v 'master$' | xargs git branch -d
# Show remote fully merged branches
echo "The following remote branches are fully merged and will be removed:"
git branch -r --merged master | sed 's/ *origin\///' | grep '^topic/'
if [ $? != 0 ]; then
exit 0
fi
read -p "Continue (y/n)? "
if [ "$REPLY" == "y" ]
then
# Remove remote fully merged branches
git branch -r --merged master | sed 's/ *origin\///' \
| grep '^topic/' | xargs -I% git push origin :%
echo "Done!"
fi
|