Created
November 28, 2012 04:20
-
-
Save conspirator/4159001 to your computer and use it in GitHub Desktop.
A quick shell script to delete local git branches en masse.
This file contains 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/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