Junior — Middle
Can you explain what the git stash command does and when it is used?
sobes.tech AI
Answer from AI
The git stash command is used to temporarily save changes in the working directory and index that are not yet ready to be committed. This allows you to clear your workspace to switch to another branch or perform other operations without losing your current unfinished changes.
When you run git stash, Git saves your changes to a special stack and reverts your working directory to the state of the last commit.
Example usage:
git stash # Saves changes
# switch to another branch
git checkout feature-branch
# return to saved changes
git stash pop # Restores changes and removes them from the stack
This is convenient if you have started working on one task but need to urgently switch to another without losing your current progress.