Skip to content

Instantly share code, notes, and snippets.

@conspirator
Created November 28, 2012 04:20
Show Gist options
  • Save conspirator/4159001 to your computer and use it in GitHub Desktop.
Save conspirator/4159001 to your computer and use it in GitHub Desktop.
A quick shell script to delete local git branches en masse.
#!/bin/bash
# ## git-chipper
#
# Author: Christopher Webb <[email protected]>
# Website: http://conspirator.co
# License: http://www.opensource.org/licenses/MIT
#
# Move to master branch. Delete all other local branches.
#
# Move to master branch
git checkout master
# Collect branches
branches=()
eval "$(git for-each-ref --shell --format='branches+=(%(refname))' refs/heads/)"
# Chip it up
for branch in "${branches[@]}"; do
old="refs/heads/"
branchName=${branch/$old/}
if [[ "$branchName" != "master" ]]; then
git branch -D $branchName
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment