If you're anything like me when it comes to coding your
git stash is likely a bit long. A quick
git stash list on any of the repos I'm currently working in will reveal a few dozen stashes.
I find stashes extremely useful when experimenting with ideas and I don't necessarily want to completely trash a previous attempt. Stashes are also useful when I need to switch to another branch to make a quick edit but I'm not ready to commit the changes on my current branch.
Over time, all of this adds up to an increasingly long stash list, several dozen or more.
git has several functions for managing the stash -
git stash clear will clear the entire stash, and
git stash drop [<stash>] will drop a specific stash - all or nothing solutions for the most part.
To fix this I've created a npm package
git-trim-stash for dropping all but the most recent N stashes.
npm install git-trim-stash -g
cd your-project-directory-with-git-repo/ git-trim-stash 10
Trims the stash to the 10 most recent stashes.
If there are less stashes than the number you want to trim a friendly message will be displayed.
The package has zero dependencies and uses Node's
child_process.exec() method for executing the git commands.
More info on the package on the npm site.