Git Stash

5 March 2022

Push

Saves local unstaged modifications to the stash list

git stash push

# => Saved working directory and index state WIP on
#    dev: 7a4586 Commit message 2

List

Lists current stash entries with indexes and commit references

git stash list

# => stash@{0}: WIP on dev: 7a4586... Commit message 2
#    stash@{1}: On master: 9cc0589... Commit message 1

Pop

Returns indexed stashed entry on top of current tree state.

Stash entry is removed from the stash list, unless a conflict prohibits the action. Working directory must match the index.

git stash pop [index]

# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git restore <file>..." to discard changes in working directory)
#         modified:   apps/app-frontend/src/App.tsx
# no changes added to commit (use "git add" and/or "git commit -a")
# Dropped refs/stash@{0} (08f01075929fef2e330d3c4f88d53c67a57a4586)

Apply

Apply stashed entry to tree, without removing from stash list.

git stash apply 0

Branch

Creates and checkout new branch with stash entry on tree. Useful if git stash apply has conflicts.

git stash branch [branch-name]

Clear

Removes all stash entries.

git stash clear

References

https://git-scm.com/docs/git-stash