Git Stash?
Git Stash
Over the last few months, Git has become an important part of my everyday work processes. git add, git commit, git push all have shortcuts on my computer but the one that has for some time alluded me has been git stash. You're deep into work on one of your projects and being a good dev you've been working in a separate branch but you just realized there's something else you'd like to do that would probably be best on its own branch but you don't want to commit the half-finished work you were just working on. The answer is git stash.
Git stash save
This command comes with various options:
git stash save "Your stash message"
Stashing untracked files
git stash save -u
# or
git stash save --include-untracked
Git stash list
When you git stash, Git creates a commit object and saves it in your repo. View your stashes:
git stash list
Git stash apply
Takes the topmost stash and applies it:
git stash apply stash@{1}
Git stash pop
Similar to apply but deletes the stash after applying:
git stash pop stash@{1}
Git stash show
Shows the summary of stash diffs:
git stash show -p
Git stash branch
Creates a new branch with the latest stash:
git stash branch <name> stash@{1}
Git stash clear & drop
git stash clear deletes all stashes. git stash drop deletes the latest one. Use with caution.
There's a lot of power within git, and Git Stash is certainly one to learn to keep your workflow moving forward.