Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

How can I temporarily set aside tracked edits with Git stash?

Quick answer

Review the repository with git status, then save tracked edits with git stash push -m "short description". Check git stash list and inspect the newest entry with git stash show stash@{0}; then run git status again. By default, stash omits untracked files, so check whether you have any. A stash is temporary storage, not a durable backup or a replacement for a commit. [S1][S2]

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

I need to switch tasks, but I’m not ready to commit my current edits. What’s a safe basic way to set aside tracked changes with Git stash?

Geez

First check what is in the working tree:

git status

Then save the tracked edits in a named stash:

git stash push -m "work on [task] before switching"

Git stash records the working-directory and index state, then returns the working tree to match HEAD. By default it does not include untracked files. [S1] The message is a label to help you recognize the entry later.

Before switching tasks, verify that Git created an entry and that its contents look right:

git stash list

git stash show stash@{0}

git status

The first command lists saved stashes; the second inspects the newest entry; the last shows the current repository status. These checks help confirm what happened, but don’t treat a stash as a durable backup.

Follow-up question

How do I tell whether I’m about to leave out files? I sometimes have new files that Git hasn’t started tracking.

Geez

Look at the git status output before stashing. It reports staged and unstaged changes and normally shows untracked files, so you can distinguish edits to tracked files from newly created files. [S2] If there are untracked files, the basic command above leaves them out. If you want to include them too, use:

git stash push --include-untracked -m "work on [task] before switching"

That option changes what the stash captures. [S1] Review the resulting stash rather than assuming every file on disk was included: ignored files are not shown by git status unless requested, so status alone is not a complete inventory. [S2] If an ignored file matters, decide separately how to preserve it before switching.

Follow-up question

Can you show the checks with an example? I want a simple way to know whether my tracked work was put aside.

Geez

Assume, for illustration, that src/report.js has tracked edits and you want to leave any untracked files out. Your checks could look like this:

git status

Review the output and note the tracked edits you expect to save. Then run:

git stash push -m "report changes before docs task"

Inspect the saved entry:

git stash list

git stash show stash@{0}

Finally:

git status

If the stash list shows the new message, the entry inspection corresponds to the expected edits, and status no longer shows those edits in the working tree, you have useful confirmation that the tracked work was stashed. This example assumes the newest entry is stash@{0}; if other stashes are being added, check the list and choose the entry you intend to inspect. A clean status alone is not proof that every file was saved.

Follow-up question

When I’m ready to return to that work, and if I need stronger preservation, what should I do?

Geez

When you return, inspect the stash entry and identify the work you want to resume. For work you need to preserve durably, make an appropriate commit or use a separate backup process. Stash is a temporary Git mechanism; the documentation does not characterize it as a durable backup. [S1]

The checks above show what Git reports about the working tree and stash, but they do not establish that every file on the computer—including ignored files—has been preserved. [S2]

A practical checklist

  • Run git status and identify the tracked edits you intend to set aside.

  • Notice any untracked files; add --include-untracked if you want them in the stash.

  • Create a named entry with git stash push -m "[short task description]".

  • Inspect git stash list and git stash show stash@{0} to check the entry.

  • Run git status again, and use a commit or separate backup for durable preservation.

A few more useful answers

Does a basic `git stash push` include untracked files?

No. By default, untracked files are not included. Use --include-untracked if you want the stash to capture them too. [S1]

Does a clean `git status` prove that everything was saved?

No. Status helps check tracked changes and normally shows untracked files, but ignored files are not shown unless requested. Inspect the stash as well, and account separately for files status does not display. [S2]

Is a stash a backup?

Treat it as temporary storage for Git work, not as a durable backup. The documentation describes stash as a temporary mechanism and does not establish it as a backup. [S1]

Sources

References used for this guide.

  1. [S1] Git: git-stash documentation
    git-scm.com · Checked
  2. [S2] Git: git-status documentation
    git-scm.com · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work