Skip to content

Instantly share code, notes, and snippets.

@cblage
Created October 10, 2014 20:59
Show Gist options
  • Save cblage/dafc1286a50221f4e745 to your computer and use it in GitHub Desktop.
Save cblage/dafc1286a50221f4e745 to your computer and use it in GitHub Desktop.
Git Prune Branches
function gitPruneBranches() {
local remote="$1"
local delete_arg="$2"
if [ -z "$remote" ]; then
echo "must define a remote"
return 1
fi
if [ -z "$delete_arg" ]; then
delete_arg="-d"
fi
echo "Pruning branches for remote=${remote}"
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep "${remote}") | awk '{print $1}' | xargs git branch "${delete_arg}"
}
alias gpb='gitPruneBranches'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment