Stash saves selected local work for later restoration. Inclusion of untracked or ignored files depends on options, and applying can conflict.
Before you start
You should understand commits, branches, the working tree and the staging area. Draw the commit graph before changing history. Try commands in a disposable repository with a clean working tree so you can observe exactly which references and files each operation changes.
The practical goal is to reason through this situation: Store unfinished tracked edits before switching work, then inspect restoration. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.
Step-by-step walkthrough
Step 1: Inventory local work
Tracked, untracked and ignored files have different capture behavior.
Step 2: Choose temporary or durable storage
A stash is useful for short interruption; a branch commit may better preserve important work.
Step 3: Inspect restoration
Applying can conflict and does not guarantee every file was saved.
Worked scenario
Store unfinished tracked edits before switching work, then inspect restoration.
An unfinished tracked edit is stashed while a new untracked helper remains outside the captured snapshot under ordinary behavior. Switching tasks without checking that helper risks losing its context. List captured changes and restore deliberately; a stash existing locally is not a shareable backup.
Common mistake
A stash is easy to forget and is not a reviewed commit or remote backup.
Verify the behavior
Inspect capture contents and restore in a disposable working tree with conflicting edits.
Interview exercise
Preserve an important work-in-progress.
Answer and reasoning
Use a deliberate branch and commit when durable, shareable history matters; verify exactly which files were captured.
Continue learning
Compare the scenario with the Git and CI/CD interview questions and test your understanding with the Git and CI/CD MCQs. For terminology and implementation details, consult the reference material.