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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.