git stash is great for when you want to save changes for later, but aren't ready to commit them yet. It's the "unmarried move-in boyfriend" of Git commands. If you're in the middle of one task, but are interrupted and need to check out another branch, you can
git stash those changes away and bring them back later.
Where do they go? Git lets you have a big list of "stashes" separate from all branches and commits. There's no limit to the number of stashes that I know of.
Here are the most useful versions of this command that I've found:
git stashwill automatically stash all untracked changes. You may need to stage any untracked files, as I've found they're not always included in the stash automatically.
git stash listshows a lit of all stashed changes. They're labelled by the branch they’re on, and that branch’s most recent commit.
- Each one has a name in this format:
#being a basic reference number.
git stash apply <name>applies the stashed changes to the current files. If it’s the most recent stashed changes under
<name>argument isn’t needed. You’ll need to resolve any merge conflicts that may pop up.
git stash pop <name>does the same as the above, but removes the stash from the list afterward.
git stash drop <name>just removes a stash from the list.