Last active
August 29, 2015 14:13
-
-
Save philangist/ac0ee2948d5c65ce61b1 to your computer and use it in GitHub Desktop.
Easily delete local and remote references to multiple git branches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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