Skip to content

Instantly share code, notes, and snippets.

@TheBox193
Created December 9, 2016 22:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save TheBox193/992eaf8d6b654dcfffc65e8decf2330d to your computer and use it in GitHub Desktop.
Save TheBox193/992eaf8d6b654dcfffc65e8decf2330d to your computer and use it in GitHub Desktop.
Selectively bulk delete git stash files.
#!/bin/bash
if [ ! -d ".git" ]; then
echo "Not a git Directory"
exit 1
fi
function getStashesToRemove {
git stash list | while read -r line;
do
read -p "remove branch: $line (y/N)?" answer </dev/tty;
case "$answer" in y|Y)
echo "$line";
esac;
done
}
REFS=($(getStashesToRemove | cut -d ':' -f 1))
for (( idx=${#REFS[@]}-1 ; idx>=0 ; idx-- )) ; do
echo "Removing ${REFS[idx]}"
git stash drop "${REFS[idx]}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment