The stash is a super-handy zone that lets us handle a sudden emergency with ease.

Let's say we're up to our eyebrows in a complex piece of work.

  1. We have ongoing work on tracked files A, B and C, plus two new (untracked) files: D and E.
  2. This batch of work is pretty involved already and we started vetting some content for the next commit by staging it in the index, namely files A, C and E. At this point, neither the index nor the Working Directory are really up for commit.
  3. So naturally this is when lightning strikes! Our boss barges in to strongarm us into dropping everything in favor of a so-called priority task on that same project, and as they're the boss, I guess they're to be obeyed? Let's say they are.
  4. So we need to set all our ongoing stuff aside in order to start working on this DEFCON 1 from a relevant clean state in our repo.  For instance, if this is a production hotfix, we need to switch to the commit currently in production before we write the patch. So we stash all our work away, including untracked files, if only to avoid committing them by mistake as part of our emergency.
  5. We can now handle the new task and commit the relevant fixes so we can share them (and possibly deploy them to production).
  6. Once the emergency is dealt with, we can restore our work from the stash and get our Working Directory (and usually our index) back in their prior state, then move on as if nothing had happened.

Sharing: sync'ing with the remote repo

Sharing work through a remote repo is easy. It’s all about sending new local references to the remote and getting new remote references in the local repo.

  1. Let’s imagine we have two coworkers, Anna and Elliott, who collaborate through a common remote conventionally named “origin”. For this example, we’ll assume they’re actually working on the same feature, not on separate areas of the project.
  2. Anna commits stuff and shares it by sending it to the server.
  3. Elliott needs that work, so he fetches it from the server into his own machine.
  4. He then commits twice locally.
  5. And shares it.
  6. In the meantime, Anna kept working and has another local commit of her own.
  7. In order to share it, she’ll need to first grab Elliott's work and replay her own work on top of it.
  8. She is then able to share her own work, and so on and so forth…