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