QA
Beginner LevelGit & GitHub

How does git stash temporarily store dirty working directory modifications?

❓ Interview Prompt: Explain git stash, saving dirty uncommitted changes, git stash pop vs apply, stashing untracked files, and stash list management.

'git stash' temporarily shelved uncommitted local modifications (both staged and unstaged files), returning your working directory to a clean HEAD state so you can switch branches cleanly.

Stash Commands:

•
'git stash' or 'git stash push -m "work in progress"': Saves modified tracked files to a local stack.
•
'git stash -u': Includes untracked files in the stash.
•
'git stash list': Displays stored stash entries ('stash@{0}', 'stash@{1}').
•
'git stash pop': Re-applies the most recent stash entry ('stash@{0}') to your working directory and deletes it from the stack.
•
'git stash apply': Re-applies the stash entry while retaining it in the stack.

Code Implementation Example

bash
# Stash uncommitted changes including untracked files with a message
git stash push -u -m "WIP: login form validation"

# Switch branches safely and return later
git switch hotfix-branch

# Switch back and restore stashed work
git switch feature-branch
git stash pop
💡Stashing dirty working directory state and restoring via git stash pop.
🎯 Interview Key Takeaway

Use git stash push -u to temporarily save dirty working state, and git stash pop to restore changes after branch switching.

#git stash#Stash Stack#Beginner
Back to all Git & GitHub Questions→

More Git & GitHub Interview Questions

Beginner LevelGit & GitHub

Compare git rebase versus git merge and explain how git bisect finds regressions.

Beginner LevelGit & GitHub

What is the difference between git init and git clone?

Beginner LevelGit & GitHub

What are the Three Trees in Git (Working Directory, Staging Area / Index, Commit History)?