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:

    git stash
    
  • To stash uncommitted changes with a message:

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

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

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

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

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

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

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

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

    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:

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

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

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

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

    git stash list