Git Developer Guide
How to find forgotten Git stashes across all repos on a Mac
Why stashes get forgotten
git stash is meant to be a thirty-second parking spot before a pull or a branch switch. Then nothing reminds you it is there: stashes do not show up in git log, git branch or plain git status, and git push never sends them anywhere.
List the stashes in one repo
git stash list --format='%gd %cr %gs'
That prints each stash's name, its age, and the branch you were on:
stash@{0} 3 weeks ago WIP on main: 2b0a582 Fix token refresh
stash@{1} 7 months ago On feature/login: half-done login fix
WIP on is Git's default message; On <branch>: means you named it with git stash push -m. To see what is inside one, including any untracked files it saved:
git stash show -p 'stash@{1}'
git stash show --include-untracked 'stash@{1}'
The quotes keep the braces literal in every shell. To have git status mention stashes from now on, run git config --global status.showStash true.
Find every repo on your Mac with stashes
find ~/Projects ~/code ~/src -maxdepth 4 -name .git -type d -prune -print0 2>/dev/null |
while IFS= read -r -d '' gitdir; do
repo=${gitdir%/.git}
count=$(git -C "$repo" stash list </dev/null | wc -l | tr -d ' ')
if [ "$count" -gt 0 ]; then
oldest=$(git -C "$repo" stash list --format='%cr' </dev/null | tail -n 1)
echo "$count stash(es), oldest $oldest: $repo"
fi
done
- Put the folders where you keep code at the start of the
findline. Ones that do not exist are silently ignored. -type dcounts each repository once: linked worktrees have a.gitfile, and share their main repository's stashes anyway.- To search your whole home folder, use
~and a larger-maxdepth. Expect it to be slow, and macOS may ask whether Terminal can access Desktop, Documents and Downloads. See how to list all Git repositories on a Mac.
Deal with each one
Pick whichever fits the stash:
git stash apply 'stash@{1}'
git stash branch rescue-login 'stash@{1}'
git stash drop 'stash@{1}'
apply restores the changes and keeps the stash. stash branch creates a new branch at the commit you originally stashed from, applies the stash there, and drops it if that worked. That is the best choice for an old stash, because it applies cleanly however far the original branch has moved on. drop deletes it once the work is committed or no longer wanted.
Recover a stash you dropped by mistake
A dropped stash is only unreferenced, not deleted. Until git gc cleans up unreachable objects (by default, ones more than two weeks old), you can find it among the unreachable commits:
git fsck --unreachable | awk '/^unreachable commit/ {print $3}' |
xargs git log --merges --no-walk --grep='^WIP on' --grep='^On ' --format='%h %cr %s'
Then put it back on the list with git stash store -m "recovered" <hash>.
The easier way: GitMon
GitMon shows a stash count on the row of every repository that has one, read straight from .git/logs/refs/stash, so its All list doubles as a stash inventory for every repo it watches. It is a count, not a stash browser: GitMon is read-only and will never apply, pop or drop a stash. Open the repo in your terminal from its row and use the commands above.