Skip to content

Instantly share code, notes, and snippets.

@alexras
Created December 17, 2011 00:30
Show Gist options
  • Save alexras/1488668 to your computer and use it in GitHub Desktop.
Save alexras/1488668 to your computer and use it in GitHub Desktop.
Similar to gist:942899, deletes all remote branches that have already been merged into master. It's just a lot more nervous about doing the deletion.
#!/bin/bash
# -*- mode: shell-script -*-
EXPECTED_ARGS=1
if [ $# -ne ${EXPECTED_ARGS} ]
then
echo "Usage: git_prune_remote <remote name>"
exit 2
fi
REMOTE_NAME=$1
for branch in `git branch -r --merged | grep ${REMOTE_NAME} | grep -v master | xargs -L1 | awk '{split($0,a,"/"); print a[2]}'`
do
while true
do
read -p "Delete merged remote branch ${branch} on ${REMOTE_NAME}? [yes|no] " yn
case $yn in
yes ) git push ${REMOTE_NAME} --delete ${branch}; break;;
no ) break;;
* ) echo "Please answer 'yes' or 'no'";;
esac
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment