BeginnerPhone
2 min
Git Stash vs Creating a Branch
GitVersion Control
Advertisement
Interview Question
When would you use git stash instead of committing to a new branch, and what are the trade-offs?
Key Points to Cover
- `git stash` saves dirty state without a commit; branch creates explicit history
- Stash is temporary and stack-based; branches are shareable and reviewable
- Use stash for quick context switches; branch for collaborative work
Evaluation Rubric
Explains stash purpose and behavior34% weight
Explains branch pros/cons33% weight
Gives correct usage scenarios33% weight
Hints
- 💡Mention `git stash list` / `stash pop` / `stash apply`.
Common Pitfalls to Avoid
- ⚠️Misusing `git stash` for significant, long-term work that should inherently be tracked on a dedicated branch.
- ⚠️Forgetting to apply or drop stashed changes, leading to a cluttered stash list and potentially lost work.
- ⚠️Not understanding that `git stash` by default does not save untracked or ignored files, requiring the `-u` or `--include-untracked` flag.
- ⚠️Committing incomplete or broken 'WIP' (Work In Progress) changes directly to a branch instead of utilizing `git stash` for a cleaner history.
- ⚠️Expecting stashed changes to be automatically synchronized or visible to collaborators, as stashes are purely local to your repository.
Potential Follow-up Questions
- ❓How do you stash untracked files?
- ❓How do you name a stash?
Advertisement