Skip to content

Instantly share code, notes, and snippets.

@jraines
Created December 27, 2011 21:19
Show Gist options
  • Save jraines/1525193 to your computer and use it in GitHub Desktop.
Save jraines/1525193 to your computer and use it in GitHub Desktop.
Go through your remote branches that contain some substring (or prefix) and prompt for deletion
#!/bin/bash
echo 'Clean up branches containing: '
read prefix
while read line; do
branch=$(echo $line | sed 's/origin\///')
echo "Delete this $line? [y/n]"
#can't just read from stdin while inside loop
read answer </dev/tty
if [ "$answer" == "y" ]; then
$(git push origin :$branch)
else
echo "skipped $line"
fi
done <<< "$(git branch -r | grep $prefix)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment