Arc 3 Quest 11

The Time Weaver

git stash - Freeze and resume your work

The staircase spirals downward into the depths of the Citadel. The air is cooler here, charged with an energy you had never felt before. The Master Archivist stops before a door adorned with an hourglass carved into the stone. He pushes it open slowly.

The room is circular, bathed in a bluish light. Luminous threads float in the air - some in motion, others frozen, suspended between two instants.

"Welcome to the Time Weaver's Workshop. Here, you will learn an art that few Archivists master: the ability to freeze your work in progress, go handle an urgent matter, then pick up exactly where you left off. Like a time mage who suspends one temporal thread to weave another. We call this the Stash."

The problem: an emergency mid-work

Imagine the situation: you are modifying an important file. Your work is not finished - you don't want to commit half-finished code. And suddenly, a critical bug is reported on another branch that must be fixed immediately.

You can't switch branches with uncommitted changes - Git might refuse or, worse, mix your current changes with the target branch.

Your options without git stash:

  • Commit unfinished work - bad idea, it pollutes the history
  • Lose your changes - obviously not
  • Use git stash - the right answer

An Archivist never leaves an unfinished scroll lying on their desk when the Council summons them urgently. They carefully store it in a temporal drawer, knowing they can retrieve it intact later.

git stash - Freeze your work in progress

The git stash command takes all your current changes (staged and unstaged) and sets them aside in a temporary stack. Your working directory becomes clean again, as if you hadn't touched anything.

git stash

It's like pressing "pause": everything is saved, but invisible. You can now switch branches safely.

Stash with a descriptive message

By default, the stash is automatically named after the last commit. But when you accumulate several stashes, it quickly becomes unreadable. Use the -m option to add a clear message:

git stash push -m "Dragon chronicle: chapter 3 in progress"

"Always name your temporal threads. A drawer without a label is a drawer where you can't find anything."

git stash list - View your stashes

The git stash list command displays all stacked stashes:

git stash list

Result:

stash@{0}: On main: Dragon chronicle: chapter 3 in progress
stash@{1}: WIP on main: abc1234 Add the title

Stashes are numbered starting from 0 (most recent). It's a stack: the last one added is on top. stash@{0} is always the most recent.

git stash show - Preview a stash

Before restoring a stash, you can see what it contains:

# Summary of modified files
git stash show

# Full diff
git stash show -p

# A specific stash
git stash show stash@{1}

It's like peeking into the drawer without taking anything out.

git stash pop - Restore and remove

The git stash pop command restores the most recent stash and removes it from the stack:

git stash pop

This is the most common operation: you get your work back and the stash disappears.

You can also restore a specific stash:

git stash pop stash@{2}

git stash apply - Restore without removing

Sometimes, you want to restore a stash but keep it in the stack (for example, to apply it on multiple branches):

git stash apply

The difference with pop:

Command Restores changes Removes the stash
git stash pop Yes Yes
git stash apply Yes No

"pop opens the drawer and empties it. apply opens the drawer and makes a copy. The drawer stays intact."

git stash drop and git stash clear - Cleaning up

To delete a specific stash without restoring it:

# Delete the most recent stash
git stash drop

# Delete a specific stash
git stash drop stash@{1}

To delete everything at once:

git stash clear

Warning: git stash clear is irreversible. All stashes are lost permanently. Only use this command when you are sure you no longer need any stash.

Stashing specific files

By default, git stash sets aside all changes. But you can target specific files:

git stash push -m "Just the report" report.txt

The other modified files stay in place. This is useful when you only want to set aside part of your work.

You can specify multiple files: git stash push -m "message" file1.txt file2.txt

The complete workflow: stash in real life

Here is the typical stash usage scenario:

1. You are working on a feature (main or feature branch)
2. Emergency! A critical bug is reported
3. git stash push -m "feature X in progress"    # freeze the work
4. git switch urgent-fix                         # switch branch
5. ... fix the bug, commit ...
6. git switch main                               # come back
7. git stash pop                                 # resume work

It's smooth, fast, and you don't lose anything.

The stash is your safety net for interruptions. Every time you need to switch context urgently, think git stash.

Practical exercise - The Dragon Emergency

You are in the middle of writing a chronicle when a messenger bursts in: a dragon has been spotted! You must set your work aside, write an alert report, then resume your chronicle.

  1. Create a repo with a first commit
  2. Start working on a chronicle (without committing)
  3. Stash the work in progress with a descriptive message
  4. Create a dragon-report branch and commit the alert report
  5. Return to main and restore your stash
  6. Finish and commit the chronicle
  7. Run the verification script

Step 1 - Create the repository and the first commit

mkdir time-weaver
cd time-weaver
git init -b main
echo "# Chronicles of the Kingdom" > chronicle.txt
echo "" >> chronicle.txt
echo "Times are calm in the kingdom." >> chronicle.txt
git add chronicle.txt
git commit -m "Create the chronicle registry"

Step 2 - Start working on a chronicle

You begin writing a new chapter:

echo "" >> chronicle.txt
echo "## Chapter 2 - The Harvest" >> chronicle.txt
echo "This year's crops are abundant..." >> chronicle.txt

Verify that you have changes in progress:

git status

You should see chronicle.txt in the modified files. Do not commit - the chapter is not finished.

Step 3 - Emergency! Stash the work

A messenger bursts into the room, out of breath: "A dragon! A dragon has been spotted in the northern mountains! The Council demands an immediate alert report!"

You must set your work aside:

git stash push -m "Chapter 2 writing in progress"

Verify that your directory is clean:

git status
git stash list

Step 4 - Handle the emergency on a new branch

git switch -c dragon-report
echo "# ALERT - Dragon Report" > alert.txt
echo "" >> alert.txt
echo "A dragon has been spotted in the northern mountains." >> alert.txt
echo "Defenses are being mobilized." >> alert.txt
git add alert.txt
git commit -m "Write the dragon alert report"

Step 5 - Return to the main branch

The emergency is handled, back to your work:

git switch main

Step 6 - Retrieve the work in progress

git stash pop

Verify that your changes are back:

git status
cat chronicle.txt

You should find chapter 2 in progress, exactly as you left it.

Step 7 - Finish and commit

echo "The granaries are full, the people are at peace." >> chronicle.txt
git add chronicle.txt
git commit -m "Write chapter 2 of the chronicles"

Step 8 - Check the history

git log --oneline --all --graph

Step 9 - Run the verification

bash verifier.sh
.\verifier.ps1

Command summary

Command Description
git stash Set aside current changes
git stash push -m "msg" Stash with a descriptive message
git stash list List all stashes
git stash show Preview a stash's content
git stash show -p View the full diff of a stash
git stash pop Restore the latest stash and remove it
git stash apply Restore the latest stash without removing it
git stash drop Delete a specific stash
git stash clear Delete all stashes
git stash push <file> Stash a specific file

The Master Archivist watches the temporal threads begin moving around you again.

"You have woven your first thread of time. You now know how to freeze your work, go handle an emergency, and pick up exactly where you left off. It's a power that seems simple on the surface, but experienced Archivists use it dozens of times a day."

He points to another workshop, further down the corridor.

"The next art you will learn is even more subtle: plucking a specific commit from one branch and transplanting it into another. But for now, savor this new mastery. The Time Weaver is only beginning their apprenticeship."