Useful techniques
In this section, we will improve our skills, learning some techniques that will come in handy in different situations.
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
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be...