Some Git Stash Commands I Find Useful
I've been trying to use git on the command line more. I think it's a good way to get an understanding of what's actually happening behind the UI. It also makes my skills a bit more portable; I can switch to a Linux machine or ssh into my Mac mini without having my preferred GUI tool, and I can better write scripts and similar tools if I know the raw commands underneath.
My preferred GUI, Fork, works really well with git stashes. I imagine other GUIs are the same - it's a really useful feature. Fork has some good features that are exposed well with the GUI, so I wanted to find the equivalents in the git CLI.
Git's stash is basically somewhere to store work in progress before you are ready to commit it. It works like a stack (Last In, First Out) - you push new entries to the top of the stack, and by default they'll be popped off the top when you run git stash pop.
Simple Stash
The simplest command is git stash, which takes everything that's not committed and adds it to a stash with a default message such as WIP on [branch] [last commit hash and message].
git stash
# Check the stash contents with `git stash list`
git stash list
stash@{0}: WIP on main: 967b760 initial commit
But I want to do more!
Stash Everything With A Message
To stash everything but make the message a bit more meaningful than just the last commit hash and message, you use the -m flag:
git stash -m "Stash my work"
# Check the stash contents with `git stash list`
git stash list
stash@{0}: On main: stash my work
Stash All Unstaged Changes
Something I do surprisingly often is stage some of my work, without yet committing it, and stash the rest. Often that's because I'm saving work that's in progress, or some notes, before committing the completed part of my current work then switching to another branch.
Stash only files that are not staged:
git stash --keep-index -m "Stash unstaged changes"
(Yes, I could also just commit the staged files then stash what's left without needing --keep-index. I don't really know why I do it this way around! But it's nice to know it's possible.)
Stash Specific Files
The above commands work on every file, or every file that's not staged. But sometimes I'll want to stash specific files rather than everything. You can list the specific files at the end of your command. BUT you need to include the push keyword, which is not required in the other examples.
Stash only specific files:
git stash push -m "Stash multiple files" src/MyFile.swift docs/README.md
If you liked this article, please consider buying me a coffee to support my writing.
Published on 18 March 2026