Stashing your changes

Git has a command that allows you to save the current state of the local working repository and go back to the last committed revision with git stash.

This is really helpful when you have to develop an urgent fix. After this, you can restore the stashed changes and continue with your development.

To use this command, just execute the following command snippet:

Erik@server:~$ git stash
#Do your fix and then unstash edit
Erik@server:~$ git stash pop

Of course, you can do more with this command, such as save a list of stashes:

Erik@server:~$ git stash
#See the list of available stashes
Erik@server:~$ git stash list
#Apply the second stash
Erik@server:~$ git stash apply stash@"1}
#Delete a stash
Erik@server:~$ git stash drop stash@"1} ...

Get Git Best Practices Guide 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.