When people think about learning to code, Git typically isn’t among the toolsets they consider from the very beginning. Many non-coders have heard about Ruby, Python, or Javascript, but Git doesn’t have the same name-recognition. Even if the name rings a bell, the usefulness of the tool isn’t obvious to someone who hasn’t spent some time working on a project.

Git (and Github) provide a way to create a record of the life stages of a project. From before being ready for the limelight, to finished product, the project commits document the project’s development stages like growth rings on a tree.

The issue with this is that commits become canonical. The entire purpose of the commit history is to have a record of completed stages. Committing changes that aren’t bug fixes of new feature implementations muddies the waters of this record and can make it harder to find the changes that resulted in these milestones.

At the same time, since not all work is completed in a single sitting, you need a reliable way to store work in progress. Commits are permanent, but work in progress should be saved in a way which is temporary. Through stashes Git makes this possible.

The basic syntax to use stash is:

$ git stash

Running git status after this will show a clean working directoy with no uncommitted changes. This allows you to clear changes from the working directory without losing them.

You can run stash multiple times, and each one will result in a new save of the current work in progress. To see what stashes you have saved run:

$ git stash list

A list of your stashes will be displayed, each preceded by a number. They’re listed in order of oldness, so the newest stash will be at the top of the list with the number 0. Higher numbers indicate older stashes.

There are two ways to access stashes:

$ git stash pop

This command will apply the most recent stash and delete it.

$ git stash apply <stashname>

This will apply the selected stash without deleting it from your stashes.

Finally, if you just want to remove a stash, use the following syntax:

$ git stash drop <stashname>