Lesson 40 of 51 ~20 min
Course progress
0%

Stashing and WIP Strategies

Learn to manage work-in-progress with Git stash. Master temporary storage techniques, branch switching without commits, and workflow optimization strategies.

Not every change deserves a commit. Sometimes you’re halfway through an experiment, or switching context to fix an urgent bug, and your working directory is a mess. You don’t want to commit this junk, but you don’t want to lose it either. Enter git stash. Stash is Git’s temporary shelf, letting you set work aside and pick it up later. Combined with WIP (Work in Progress) strategies, it gives you freedom to juggle tasks without polluting history.


What Is Git Stash?

Stash saves your working directory and staging area changes into a stack. It clears your working tree, leaving you clean to switch branches or pull updates. Later, you can reapply the stashed changes.

Visualization:

flowchart TD
  WD[Working Dir messy] -->|stash| Shelf[Stash Stack]
  Shelf -->|apply/pop| WD

Basic Stash Workflow

Stash your changes:

git stash

List stashes:

git stash list

Apply the latest stash:

git stash apply

Remove stash after applying:

git stash pop

Drop without applying:

git stash drop

Stashing with Messages

Label your stash for clarity:

git stash push -m "WIP: new login UI"

List shows:

stash@{0}: On main: WIP: new login UI

This makes juggling multiple stashes manageable.


Stash Specific Files

You can stash only certain files:

git stash push app.py

This stashes only changes in app.py, leaving other edits intact.


Applying Stash to Another Branch

Stash lets you teleport changes across branches. Example:

git stash push -m "WIP: refactor"
git checkout feature/refactor
git stash apply

Your unfinished work moves with you.

Visualization:

flowchart LR
  MainBranch[main messy work] -->|stash| Shelf[stash]
  Shelf -->|apply| FeatureBranch[feature branch]

Work in Progress (WIP) Commits

An alternative to stash is making temporary commits marked “WIP.”

git add .
git commit -m "WIP: partial implementation"

Later, you squash or amend them during cleanup. This keeps progress visible but acknowledges it’s unfinished.


Choosing Between Stash and WIP

  • Stash: temporary, invisible in history, good for quick context switches.
  • WIP commits: visible, good when you want checkpointed progress.

Some teams discourage stash because it hides progress. Others embrace it for flexibility.


Solo Workflow Example

You’re coding a new feature when a bug report comes in. You stash:

git stash push -m "WIP: feature X"
git checkout hotfix
# fix bug, commit, push
git checkout feature-X
git stash pop

You resume right where you left off.


Team Workflow Example

On a team, WIP commits are safer. Everyone sees your in-progress work. Later, you squash them into meaningful commits with rebase. This avoids the risk of losing stashed changes.

Example cleanup:

git rebase -i HEAD~3

Squash 3 WIP commits into 1 polished commit.


Strategies for Discipline

  • Never leave stashes forgotten—clean them regularly.
  • Prefix WIP commits clearly.
  • Don’t stash secrets or long-term experiments—commit them to a branch.
  • Automate cleanup: some CI tools warn if stashes remain.

Think Different Mindset

Stash and WIP teach a balance: not every act deserves permanence, but not every act should vanish. Some work belongs in drafts, others in history. Git lets you choose. Think of stash as your sketchbook, WIP as your rough draft, and commits as your published chapters.


Stash is your safety net, WIP commits are your scaffolding. Both let you juggle messy reality with clean history. Use them wisely, and you’ll never again fear losing half-finished work. In the next chapter, we’ll explore bisect and see how Git can become a detective to hunt down bugs in history.