How to Stash with Message in Git: Simple Guide
Use
git stash push -m "your message" to save your current changes with a descriptive message. This helps you remember what you stashed later when you list or apply stashes.Syntax
The basic syntax to stash changes with a message is:
git stash push -m "message": Saves your current changes with a custom message.git stashalone saves changes without a message.
bash
git stash push -m "your message here"
Example
This example shows how to stash changes with a message and then list the stashes to see the message.
bash
git stash push -m "WIP: fixing login bug" git stash list
Output
stash@{0}: On main: WIP: fixing login bug
Common Pitfalls
Common mistakes when stashing with a message include:
- Forgetting the
-mflag, which results in no message saved. - Using
git stash save "message"which is a legacy command and may be deprecated. - Not checking the stash list to confirm your message was saved.
bash
git stash save "WIP: fixing login bug" # Legacy, avoid this # Correct way: git stash push -m "WIP: fixing login bug"
Quick Reference
| Command | Description |
|---|---|
| git stash push -m "message" | Stash changes with a custom message |
| git stash list | Show all stashes with messages |
| git stash apply stash@{0} | Apply a specific stash by index |
| git stash drop stash@{0} | Remove a specific stash |
Key Takeaways
Use
git stash push -m "message" to save changes with a clear message.Always check your stashes with
git stash list to see messages.Avoid using the legacy
git stash save command.Messages help you remember the purpose of each stash.
Use stash messages to organize your work when switching tasks.