What is `git stash`?
git stash is a mechanism for temporarily saving uncommitted changes to clean the working directory and bring those changes back later.
What git stash does
The command:
bash
git stashGit:
- saves changes from the working directory and staging area into temporary storage
- clears the working directory
- returns the repository to the state of the last commit
Changes are not lost and do not become part of the commit history.
Why git stash is needed
git stash is used when you need to:
- temporarily switch to another branch
- postpone unfinished work
- quickly clean the working directory without a commit
Main operations
bash
git stash # save changes
git stash list # list saved stashes
git stash apply # apply a stash (without removing it)
git stash pop # apply and remove a stash
git stash drop # remove a stashWhat is important to know
- a stash is stored locally
- a stash is not a commit
- a stash is not transferred via
push - multiple stashes can be kept
A key phrasing for an interview
git stashlets you temporarily save uncommitted changes and clean the working directory, so you can later bring those changes back without creating a commit.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.