Data report"State of code review 2024" is now liveRead the full report

Best practices for naming stashes in Git

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


git stash is a feature in Git that allows developers to temporarily save the current state of the working directory and the index (staging area), without committing the changes to the repository's history. This can be particularly handy when you need to switch contexts quickly, but it's important to manage these stashes effectively to avoid confusion later on, especially in complex projects or when collaborating with others.

While Git automatically assigns each stash a numeric index and a message derived from the commit message of the HEAD at the time of stashing, these default names can be vague and unhelpful, especially when revisiting stashes after some time. Naming your stashes can provide clearer context about what each stash contains, making it easier to decide when to apply or drop a stash.

When naming your stashes, aim for clarity and brevity. The name should give a clear idea of what the stash involves without being overly verbose. For example:

  • Bad: Stash 1
  • Good: Fix for issue #42

If your work relates to a specific issue or ticket, include this number in the stash name. This makes it easier to correlate stashes with particular tasks or bugs:

Terminal
git stash save "Issue #123 - add login button"

Use action words that describe what the stash does or what its changes aim to accomplish. This is especially useful in collaborative environments:

Terminal
git stash save "WIP: refactor user authentication module"

If a stash represents an incomplete feature or a work in progress, prefixing it with WIP: (Work In Progress) can be very helpful:

Terminal
git stash save "WIP: redesign of homepage"

If you often work across multiple branches, including the branch name in the stash description can prevent confusion:

Terminal
git stash save "feature-branch - finalize checkout process"

In situations where timing is crucial, such as stashes that should be applied or reviewed by certain deadlines, including a timestamp can be beneficial:

Terminal
git stash save "2024-07-01 - end of quarter updates"

Good naming is just one part of effective stash management. Regularly review your list of stashes:

Terminal
git stash list

Decide whether to keep, apply, or drop each stash based on its relevance and recency. Naming them properly initially helps make these decisions quicker and more accurately.

If you’re working in a team, ensure everyone is aware of the naming conventions for stashes. Consistency across the team helps everyone understand each other's stashes more easily and reduces the overhead of managing them.

For more information see this guide on stashing in Git.

Git gud
"It's the first Git workflow I've used that actually feels good."
–@robboclancy
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2