Skip to content

Instantly share code, notes, and snippets.

@philangist
Last active August 29, 2015 14:13
Show Gist options
  • Save philangist/ac0ee2948d5c65ce61b1 to your computer and use it in GitHub Desktop.
Save philangist/ac0ee2948d5c65ce61b1 to your computer and use it in GitHub Desktop.
Easily delete local and remote references to multiple git branches
#!/bin/sh
function usage
{
echo "usage: ./delete_stale_branches.sh [--help] [--branches [<branch_names>]]"
}
function delete_branch
{
branch_name=$1
git checkout "remotes/origin/$branch_name"
git checkout -b "$branch_name"
git checkout master
git push origin ":$branch_name"
git branch -D "$branch_name"
}
function main
{
for branch_name in "$@"
do
echo "Deleting stale branch $branch_name..."
delete_branch $branch_name
done
}
case $1 in
--help)
usage
exit 0 ;;
--branches)
shift
main $@ ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment