Skip to content

Instantly share code, notes, and snippets.

@BenjaminVanRyseghem
Last active May 25, 2016 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenjaminVanRyseghem/9e66454f949e9465b2b9ee1b9d3b98dc to your computer and use it in GitHub Desktop.
Save BenjaminVanRyseghem/9e66454f949e9465b2b9ee1b9d3b98dc to your computer and use it in GitHub Desktop.
Script to delete branches that have been merged (and are "gone").
#!/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
@BenjaminVanRyseghem
Copy link
Author

Install this script and add it to git with:

git config --global alias.clean-branches '!/path/to/git-prune-branches.sh'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment