Sometimes, you just need to grab all your changes in a Git repo—tracked, untracked, staged, everything—and move them somewhere else. After playing around with a bunch of methods, I’ve settled on a super simple solution: stashing + exporting.
Here’s how it works and why I love it.
First, it’s easy. You don’t need to mess with fancy commands or worry about missing files. It just works. Second, it’s safe—your stash is like a little safety net you can restore anytime. And honestly, it’s just nice not to have to think too hard about this stuff.
Stash Everything
Run this command to stash all your changes, including untracked files:
git stash push --include-untracked
Want to go even further and include files ignored by .gitignore
? Use this:
git stash push --all
Now all your changes are tucked away in the stash.
Check Your Stash
To make sure everything’s safe, list your stashes:
git stash list
You’ll see something like this:
stash@{0}: WIP on main: Save current work
The stash@{0}
bit is the ID you’ll need.
Export the Stash
Create a patch file with everything in the stash:
git stash show -p stash@{0} > export.patch
This will save all your changes into export.patch
. Super easy.
(Optional) Reapply the Stash
If you want your changes back in your working directory, just run:
git stash apply stash@{0}
(Optional) Clean Up
Once you’ve exported and don’t need the stash anymore, you can delete it:
git stash drop stash@{0}
When you’re ready to use your exported changes:
export.patch
file to wherever you need it.git apply export.patch
Done! Your changes are restored exactly as they were. 🎉
It’s quick. It’s simple. And it works every time. I’ve tried other approaches—like git diff
with untracked files—but they always felt clunky. Stash + export is my go-to now, and I’ve never looked back.
So, next time you need to grab all your Git changes and move them somewhere else, give this a shot. It’s saved me a ton of hassle, and I’m sure it’ll do the same for you. 😊