Git stash - putting changes temporally aside

It sometimes happens that you need to switch branches for a moment, but some changes are in progress in the current branch. To put aside those changes for a while, we can use the git stash command: let's give it a try in our grocery repository.

Append a new fruit to the shopping list, then try to switch branch; Git won't allow you to do so, because with the checkout you would lose your local (not yet committed) changes to the shoppingList.txt file. So, type the git stash command; your changes will be set apart and removed from your current branch, letting you switch to another one (berries, in this case):

[1] ~/grocery (master) $ echo "plum" >> shoppingList.txt [2] ~/grocery (master) $ git status ...

Get Git Essentials - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.