Skip to content

Instantly share code, notes, and snippets.

@simonthompson99
Last active January 15, 2021 11:42
Show Gist options
  • Select an option

  • Save simonthompson99/00037ae9bb209c62352a5da51f1ef511 to your computer and use it in GitHub Desktop.

Select an option

Save simonthompson99/00037ae9bb209c62352a5da51f1ef511 to your computer and use it in GitHub Desktop.
[git stash commands] Commands for using git stash #git #cheatsheet #workflow

View stashes and differences

  • git stash list see what is in the stash list
  • git stash show -p see full diff of the stash (add specific stash, otherwise will be most recent)

Stash stuff

  • git stash stash all changes to tracked files and revert to HEAD, add -m <message> to give an accompany description, and can specify some filepaths to limit the stash to
  • git stash -p go through hunk by hunk and decided what to stash

Applying stashes

  • git stash pop <stash> apply the stash to the current working directory, if no stash given then applies most recent one
  • git stash apply <stash> to apply the stash without removing it from the list so can be applied to multiple branches
  • git stash branch <branch_name> <stash> pop the stash onto a new branch made from the commit on which the stash was made, useful for if you make changes to the files which are in the branch since creating it (and would therefore get conflicts when trying to pop the stash)

Cleaning up

  • git stash clear removes all the stashes
  • git stash drop <stash> removes a specific stash from the stash list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment