How to do it...

With the preceding state of our repository, we can stash away the changes so that we can work on something else. The basic command will put away changes from the staging area and changes made to tracked files. It leaves untracked files in the working directory:

$ git stash
Saved working directory and index state WIP on master: d611f06 Update foo and bar
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
    
  Untracked files:
    (use "git add <file>..." to include in what will be committed)
    
      new_file
    
nothing added to commit but untracked files present (use "git add" to track)  

We can now work on something else and create and commit those changes. We'll change the first line of the foo file and create a commit ...

Get Git Version Control Cookbook 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.