Skip to content

Instantly share code, notes, and snippets.

@erykpiast
Created August 4, 2016 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save erykpiast/beb2fac2dd1fa76085b5739cfa2d88ca to your computer and use it in GitHub Desktop.
Save erykpiast/beb2fac2dd1fa76085b5739cfa2d88ca to your computer and use it in GitHub Desktop.
git_clean_local_branches
#!/bin/bash
function git_clean_local_branches {
TO_REMOVE=`git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}'`;
TO_REMOVE_LINES=`git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | wc -l`
if [ "$TO_REMOVE_LINES" -ne 0 ]; then
echo "Removing branches..."
printf "\n$TO_REMOVE\n\n";
echo "Proceed?";
select result in Yes No; do
if [[ "$result" == "Yes" ]]; then
echo "Removing in progress..."
echo "$TO_REMOVE" | xargs git branch -d;
if [ $? -ne 0 ]; then
echo "Some branches was not removed, you have to do it manually!"
else
echo "All branches removed!"
fi
fi
break;
done;
else
echo "You have nothing to clean"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment