Q: You're halfway through coding a feature when an urgent bug report comes in. You need to switch branches immediately, but your changes aren't ready to commit. How do you save your in-progress work?
Use git stash to save your uncommitted changes onto a stack without committing them:
#Git #Stashing, Tags & Everyday Workflows #L1 #Version Control #Collaboration
🎙️ Candidate Opening & Architectural Context
""In a fast-paced team with dozens of pull requests merged daily, Git workflow hygiene was critical. The interviewer is testing: Practical understanding of `git stash` and its usage patterns.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third.""
Advertisement
🛠️ Production Runbook & Step-by-Step Resolution
1️⃣
Initial Diagnostics & Root Cause Analysis
Use git stash to save your uncommitted changes onto a stack without committing them:
git stashsaves both staged and unstaged changes to tracked files. Untracked files are not stashed by default — add-u(or--include-untracked) to include them. Add-ato also include ignored files.git stash listshows all stashes. They're numberedstash@{0},stash@{1}, etc.git stash popapplies the most recent stash and removes it from the stack.git stash applyapplies it but keeps it on the stack — safer if you want to apply the same stash to multiple branches.
2️⃣
Remediation & Permanent Safeguards
Key details: Don't use stash as long-term storage — stashes are easy to forget. If the work will sit for more than a few hours, commit it on a throwaway branch instead.
git stash push -m "WIP: user profile feature"
git switch hotfix/critical-bug
# ... fix the bug, commit, push ...
git switch feature/user-profile
git stash pop
git stash drop stash@{2}removes a specific stash.git stash clearremoves all.- You can create a branch directly from a stash:
git stash branch new-branch stash@{0}— useful if the stash conflicts with current work.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: git stash saves both staged and unstaged changes to tracked files. Untracked files are not stashed by default — add -u (or --inclu."
⚡ 60-Second Elevator Pitch Talking Points
- git stash saves both staged and unstaged changes to tracked files. Untracked files are not stashe...
- git stash list shows all stashes. They're numbered stash@{0}, stash@{1}, etc.
- git stash pop applies the most recent stash and removes it from the stack. git stash apply applie...
Advertisement