Last active
May 25, 2016 10:04
-
-
Save BenjaminVanRyseghem/9e66454f949e9465b2b9ee1b9d3b98dc to your computer and use it in GitHub Desktop.
Script to delete branches that have been merged (and are "gone").
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/sh | |
git fetch -p > /dev/null 2>&1 | |
branches=`git branch -vv | grep ': gone]' | awk '{print $1}'` | |
if [[ -z "$branches" ]] | |
then | |
echo "No branch to prune" | |
exit 0 | |
fi | |
echo "You are about to delete those branches:" | |
for branch in $branches; do echo $branch; done | |
echo | |
read -p "Are you sure? " -n 1 -r | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
for branch in $branches; do git branch -D $branch; done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install this script and add it to git with: