More About Stash
List, messages and new files.
Stash has a few more tricks. You can keep several stashes, give them names, and include brand new files.

- Several stashes
- Named stashes
- New files too
New files and messages
By default, stash ignores new, untracked files. Here, our new gallery page would be left behind. Dash u includes untracked files. And push dash m adds a message, so we remember what it was. Git stash list shows our stash, with its message.
git status --short M index.html ?? gallery.html git stash push -u -m "gallery work in progress" Saved working directory and index state On main: gallery work in progress git stash list stash@{0}: On main: gallery work in progress
Choosing a stash
With several stashes, each gets a number, starting from zero, the newest. Git stash show, with dash p, previews what's inside one. Git stash apply brings changes back, but keeps them on the shelf too, in case you need them again. And git stash drop deletes one.
git stash list stash@{0}: On main: new intro stash@{1}: On main: footer color git stash show -p stash@{1} diff --git a/style.css b/style.css index 693ce9b..d38dc23 100644 --- a/style.css +++ b/style.css @@ -1 +1,2 @@ body { font-family: sans-serif; } +footer { color: gray; } git stash apply stash@{1} On branch main Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: style.css no changes added to commit (use "git add" and/or "git commit -a") git stash drop stash@{1} Dropped stash@{1} (d0f6933b2a2257f8ed64eab837a28957504d7fd9)
Stash commands
Here are the stash commands together. Stash, or stash push, saves. Pop restores and removes. Apply restores and keeps. List shows them all. Drop deletes one.
| Command | What it does |
|---|---|
| git stash push -u -m "msg" | save, with new files and a message |
| git stash pop | restore and remove |
| git stash apply | restore and keep |
| git stash list | show all stashes |
| git stash drop | delete one |
Summary
Use dash u for new files, dash m for a message, list to see them, and apply or pop to bring them back. Next, another way to combine branches. Rebase.
Key takeaways- -u: include new files
- -m: add a message
- apply keeps, pop removes