Stash changes for later

Use git stash when you want to change to a different branch, and you want to store changes that are not ready to be committed.

  • To stash uncommitted changes without a message:

    Copy to clipboard
    git stash
  • To stash uncommitted changes with a message:

    Copy to clipboard
    git stash save "this is a message to display on the list"
  • To retrieve changes from the stash and apply them to your branch:

    Copy to clipboard
    git stash apply
  • To apply a specific change from the stash to your branch:

    Copy to clipboard
    git stash apply stash@{3}
  • To see all of the changes in the stash:

    Copy to clipboard
    git stash list
  • To see a list of changes in that stash with more information:

    Copy to clipboard
    git stash list --stat
  • To delete the most recently stashed change from the stash:

    Copy to clipboard
    git stash drop
  • To delete a specific change from the stash:

    Copy to clipboard
    git stash drop <name>
  • To delete all changes from the stash:

    Copy to clipboard
    git stash clear
  • To apply the most recently stashed change and delete it from the stash:

    Copy to clipboard
    git stash pop

If you make a lot of changes after stashing your changes, conflicts might occur when you apply these previous changes back to your branch. You must resolve these conflicts before the changes can be applied from the stash.

Git stash sample workflow

To try using Git stashing yourself:

  1. Modify a file in a Git repository.

  2. Stash the modification:

    Copy to clipboard
    git stash save "Saving changes from edit this file"
  3. View the stash list:

    Copy to clipboard
    git stash list
  4. Confirm there are no pending changes:

    Copy to clipboard
    git status
  5. Apply the stashed changes and drop the change from the stash:

    Copy to clipboard
    git stash pop
  6. View stash list to confirm that the change was removed:

    Copy to clipboard
    git stash list