• Pricing
DashboardContact Sales
  • Blogs
  • Discover
  • Docs
  • Community
  • AgentBeta
⌘K

Over 80,000,000 Cloud Servers Launched

Over 80,000,000 Cloud Servers Launched

Cloud ComputeCloud GPUBare MetalFile SystemObject StorageBlock StorageManaged DatabasesCDNServerlessKubernetesContainer RegistryDirect ConnectLoad Balancers
RegionsAdvanced NetworkControl PanelOperating SystemsUpload ISO
Industry CloudOne-Click DeploymentUse Cases
Browse AppsBecome a Vendor
FAQDevelopers / APIsVultr DocsServer StatusBug BountyPromotionsSolution PartnersStart-Up Programs
Our TeamNewsBrand AssetsReferral ProgramCreator ProgramCareersSLALegalVultr Trust CenterContactYour Privacy ChoicesSubprocessorsAccessibility
Contact SalesSign Up

© Vultr 2026 | VULTR is a registered trademark of The Constant Company, LLC.

Terms of ServiceAUPDMCAPrivacy PolicyCookie Policy

In this Article

Git Stash Common CommandsManage Multiple StashesClean Your StashStash Untracked or Ignored FilesConclusion
  1. Docs
  2. Articles & Guides
  3. Development

How to Stash Changes in Git

7 min readUpdated 18 July 2025
0 comments
How to Stash Changes in Git header image

Git stash lets you temporarily store uncommitted changes in your working directory. This is useful when you need to switch tasks or branches without committing incomplete work. When you run git stash, Git saves your staged and unstaged changes to a stack and removes them from your working copy so you can apply them later.

This article explains how to use git stash to save your progress, apply or drop stashes, include untracked files, and manage multiple stashed changes effectively.

Git Stash vs Git Commit

FeatureGit StashGit Commit
PurposeTemporarily saves changes without committingPermanently records changes in the repository
Usage ScenarioWhen switching tasks or branches mid-workWhen a change is complete and ready to be saved
Affects HistoryNoYes - adds to project history
Includes Untracked FilesOptional (with flags like --include-untracked)Yes, if added with git add
RecoveryCan apply or drop laterCan revert or reset, but part of history
Typical Commandgit stashgit commit -m "message"

The Short Answer Version


# Stash all changes (staged and unstaged)
$ git stash

# Stash changes with a custom message
$ git stash push -m "Work in progress"

# List all stashes
$ git stash list

# Apply the most recent stash from the stack and remove it
$ git stash pop

# Drop a specific stash
$ git stash drop stash@{1}

# Clear all stashes
$ git stash clear

Command Syntax

git stash [OPTIONS]

Where:

  • [OPTIONS]: These control how the stash command works. Options are explained in the sections below.
    • save: This command saves your local changes (staged and unstaged) to the stash stack.
    • pop: Applies the most recent stash and removes it from the stash stack.
    • apply: Applies the most recent stash without removing it from the stack.
    • list: Lists all the stashes saved in your repository.
    • show: Shows the details of the most recent stash or a specific stash.
    • drop: Deletes a specific stash from the list.

Git Stash Common Commands

  • Stash all changes (staged and unstaged).

    CONSOLE
    $ git stash
    Powered by Vultr AgentBeta

    Saves all uncommitted changes and restores your working directory to the last commit.

  • Stash with a message.

    CONSOLE
    $ git stash push -m "message"
    Powered by Vultr AgentBeta

    Saves your changes along with a descriptive message for identification later.

  • Include untracked files.

    CONSOLE
    $ git stash -u
    Powered by Vultr AgentBeta

    Stashes both tracked and untracked files.

  • List all stashes.

    CONSOLE
    $ git stash list
    Powered by Vultr AgentBeta

    Displays all the stashes saved in your working directory, with identifiers like stash@{0}.

  • Show the changes in the latest stash.

    CONSOLE
    $ git stash show
    Powered by Vultr AgentBeta

    Displays a summary of the changes in the most recent stash.

  • Show the full diff of the latest stash.

    CONSOLE
    $ git stash show -p
    Powered by Vultr AgentBeta

    Displays a detailed diff of the changes in the most recent stash.

  • Apply the most recent stash.

    CONSOLE
    $ git stash apply
    Powered by Vultr AgentBeta

    Restores the changes from the most recent stash but keeps it in the stash list.

  • Apply and remove the most recent stash.

    CONSOLE
    $ git stash pop
    Powered by Vultr AgentBeta

    Applies the most recent stash and removes it from the stash list.

  • Create a new branch from a stash.

    CONSOLE
    $ git stash branch <branch-name>
    Powered by Vultr AgentBeta

    Creates a new branch, applies the stash, and removes it if successful.

Explanation of Flags

  • -u or --include-untracked: This flag allows you to stash untracked files in addition to changes to tracked files.
  • -m: This option lets you add a custom message when saving a stash, making it easier to identify later.
  • -p: Enables interactive mode, allowing you to choose specific changes (hunks) to stash. This is ideal when your working directory contains unrelated edits and you only want to stash a subset.

Manage Multiple Stashes

When working on multiple tasks or features, you may stash changes several times before returning to them. Git saves these entries in a stack-like structure, each assigned a unique reference in the format stash@{n}, where n is the index starting at 0 (most recent first). This section explains how to identify, apply, and remove specific stashes to streamline your workflow.

Command Usage

  • To view all saved stashes in your repository, run.

    CONSOLE
    $ git stash list
    Powered by Vultr AgentBeta

    Displays all stashes, showing each stash's reference, description, and the branch where the stash was created.

  • To restore changes from a specific stash without removing it from the stack.

    CONSOLE
    $ git stash apply stash@{n}
    Powered by Vultr AgentBeta

    This command applies the changes from stash@{n} where n is the stash number but retains it in your stash list for potential reuse or inspection.

  • To drop a specific stash.

    CONSOLE
    $ git stash drop stash@{n}
    Powered by Vultr AgentBeta

    Removes a specific stash from the stash list.

  • To permanently delete all stashed entries.

    CONSOLE
    $ git stash clear
    Powered by Vultr AgentBeta

    This command removes all the stashes from the stash list.

    Warning

    git stash clear permanently deletes all stash entries and cannot be undone. Always double-check your stash list before clearing.

Command Demonstration

Follow this workflow to create, apply, and clean up multiple stashes:

  1. Modify multiple files in your working directory.

    CONSOLE
    $ echo "<h1>Header</h1>" > index.html
    $ echo "console.log('Debug');" > app.js
    Powered by Vultr AgentBeta
  2. Stash the current changes with a description.

    CONSOLE
    $ git stash push -m "UI update: Header and debug script"
    Powered by Vultr AgentBeta

    Output:

    Saved working directory and index state On main: UI update: Header and debug script
  3. Make more changes and stash again.

    CONSOLE
    $ echo "<footer>Footer</footer>" >> index.html
    $ git stash push -m "Added footer component"
    Powered by Vultr AgentBeta

    Output:

    Saved working directory and index state On main: Added footer component
  4. List all stashes to review saved changes.

    CONSOLE
    $ git stash list
    Powered by Vultr AgentBeta

    Output:

    stash@{0}: On main: Added footer component
    stash@{1}: On main: UI update: Header and debug script
  5. Apply the second stash (older one) without removing it.

    CONSOLE
    $ git stash apply stash@{1}
    Powered by Vultr AgentBeta

    Output:

    On branch main
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)
            modified:   app.js
            modified:   index.html

    The stash is applied, but remains in the stash list.

  6. Manually remove the applied stash when no longer needed.

    CONSOLE
    $ git stash drop stash@{1}
    Powered by Vultr AgentBeta

    Output:

    Dropped stash@{1} (0b08178cfade68....)

Clean Your Stash

As you work on multiple tasks or features, your stash list can grow with changes you've saved for later. To avoid confusion and keep your development workflow organized, Git provides commands to drop individual stashes or clear the entire stash stack. This section explains how to clean up your stash history and demonstrates a safe, practical cleanup workflow.

Command Usage

  • To remove a specific stash.

    CONSOLE
    $ git stash drop stash@{n}
    Powered by Vultr AgentBeta

    This above command removes the stash entry at the specified index stash@{n} without affecting others.

  • To remove the most recent stash (top of the stack).

    CONSOLE
    $ git stash drop
    Powered by Vultr AgentBeta

    Omitting the index defaults to stash@{0}.

  • To remove all stashes from the stash list.

    CONSOLE
    $ git stash clear
    Powered by Vultr AgentBeta

    Warning

    git stash clear permanently deletes all stash entries and cannot be undone. Always verify your list before clearing.

Command Demonstration

Follow this example to apply, commit, and clean up stash entries effectively:

  1. List all the available stash entries.

    CONSOLE
    $ git stash list
    Powered by Vultr AgentBeta

    Your output should be similar to the one below:

    stash@{0}: On main: Recent component styling
    stash@{1}: On main: API endpoint integration
    stash@{2}: On dashboard-feature: Error handling fix
  2. Apply and remove the third stash (older entry).

    CONSOLE
    $ git stash pop stash@{2}
    Powered by Vultr AgentBeta

    This above command apply the stash@{2} on index 2 and removes it from the stash list.

  3. Commit the Restored Changes.

    CONSOLE
    $ git commit -am "Fix error handling in authentication flow"
    Powered by Vultr AgentBeta
  4. Delete another stash that's no longer needed.

    CONSOLE
    $ git stash drop stash@{1}
    Powered by Vultr AgentBeta

    Note

    When you drop a stash, the remaining stashes are renumbered. For example, if you delete stash@{1}, then stash@{2} becomes the new stash@{1}.

  5. Remove all the stashes from the stash list.

    CONSOLE
    $ git stash clear
    Powered by Vultr AgentBeta

Stash Untracked or Ignored Files

By default, git stash only saves changes to tracked files. If you want to preserve new or ignored files as well, use the appropriate flags to include them in the stash.

  • Use the -u (or --include-untracked) flag to stash both tracked changes and untracked files.

    CONSOLE
    $ git stash push -u
    Powered by Vultr AgentBeta

    Saves all changes, including files not yet staged or committed.

  • To stash everything, including files listed in .gitignore, use the -a (or --all) flag.

    CONSOLE
    $ git stash push -a
    Powered by Vultr AgentBeta

    Warning

    This will stash build artifacts, dependencies, and other ignored files. Use with caution.

  • To inspect a stash that includes untracked content, use.

    CONSOLE
    $ git stash show -p -u stash@{0}
    Powered by Vultr AgentBeta

    Displays the full patch, including untracked files stored in the specified stash.

Command Demonstration

Follow this example to stash and restore tracked and untracked files.

  1. Check your status in the working directory.

    CONSOLE
    $ git status
    Powered by Vultr AgentBeta

    Your output should be similar to the one below:

    On branch main
    Changes not staged for commit:
            ......
            modified:   user-profile.html
    Untracked files:
            ......
            login-validation.js
  2. Stash all changes, including untracked files.

    CONSOLE
    $ git stash push -u -m "WIP: Auth validation script"
    Powered by Vultr AgentBeta
  3. Verify your working directory is clean.

    CONSOLE
    $ git status
    Powered by Vultr AgentBeta

    Output:

    On branch main
    nothing to commit, working tree clean
  4. Restore the changes from stash.

    CONSOLE
    $ git stash pop
    Powered by Vultr AgentBeta

    Your output should be similar to the one below:

    On branch main
    Changes not staged for commit:
            ......
            modified:   user-profile.html
    
    Untracked files:
        ......
            login-validation.js
    Dropped refs/stash@{0} (17251bf54e3861fe6233d9450740f253ced4ac80)

    With these flags, and by following the steps above, you can stash your full working state — including files Git doesn't track — and restore it later without losing any progress.

Conclusion

In this article, you learned how to use git stash to save uncommitted changes, manage multiple stashes, include untracked or ignored files, and resolve common stash-related issues. Whether you're switching tasks, cleaning your working directory, or pausing work in progress, stashing helps you stay organized without committing incomplete code.

Tags:Git

Tech Talk: Running a Self-Improving AI Agent with Hermes on Vultr

Have a suggestion or found an issue with this article?

About the Author

SO

Stella Oiro

View Profile
View Profile

More to Explore

Show More
tech-talk-thumbnail

Tech Talk: Running a Self-Improving AI Agent with Hermes on Vultr

tech-talk-thumbnail

Tech Talk: Implementing Fine-Grained Access Control with Vultr IAM

tech-talk-thumbnail

Tech Talk: Getting Started with Vultr IAM

tech-talk-thumbnail

Tech Talk: Simplifying Zero-Trust Networking with NetBird on Vultr Marketplace

Show More

0 Comments

Start the conversation

Be the first to comment and share your perspective with the community.