Skip to content

Instantly share code, notes, and snippets.

@valsaven
Forked from TheBox193/gitDeleteMultiStash.sh
Created May 19, 2021 08:25
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 valsaven/ea71cf86569d55cdb57afaef610a560b to your computer and use it in GitHub Desktop.
Save valsaven/ea71cf86569d55cdb57afaef610a560b 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