Red Green Repeat Adventures of a Spec Driven Junkie

TWIL: git stash

tldr; This Week I Learned to integrate git stash better into my programming work flow:

  • Basically, I name stashes using: git stash save 'name'
  • List stashes: git stash list
  • Apply a stash: git stash apply stash@{n)

Why??

Using stashes helps me:

  1. naming my stashes so I know what they were used for (i.e. debugging, local dev, redirect print output)
  2. reuse stashes between commits and feature builds

When I know what a stash does (via its name,) instead of popping the stash off, I can apply the stash over and over again.

I found applying a stash to a project useful when the stash contains code for a specific part of the project. This saves me a lot of effort in remembering how to ‘setup’ code, like working locally instead of on production.

Sometimes, this code saved in stashes should NEVER be committed to the project, but is still useful in the process of development.

How

Only three git commands are needed:

  1. git stash save 'name'
  2. git stash list
  3. git stash apply stash@{n}

When I want to create a ‘save point’ in my code I use git stash save 'name' where name is a specific name I give it (i.e. output image saved to file instead of sending to printer.)

I look up stashes to remember what stashes I have: git stash list. With the names used in step 1, I can see what each stash is used for.

When I want to reapply a stash’s code, I use: git stash apply stash@{n} where n is the number from the stash list command.

What

I learned three new git commands to help improve my coding by saving specific code to a local stash so it can be reapplied over and over again.