git stash untracked files

Greg Foster
Greg Foster
Graphite software engineer

In Git, stashing allows you to clear your working directory and switch branches without losing your current work. However, by default, git stash does not include untracked files (files that are new or are explicitly ignored by Git). This guide explains how to include untracked files in your stash, ensuring that all aspects of your current work can be saved temporarily.

git stash temporarily shelves (or stashes) changes you've made to your working directory so you can work on something else, and then come back and re-apply them later on. The stashed changes are saved on a stack, where you can reapply them as needed.

To stash changes, including untracked files, you need to use the --include-untracked or -u option with git stash. This command saves both your staged and unstaged changes, as well as any files in the working directory that Git is not tracking.

To stash your local changes, along with untracked files, run:

git stash -u

After stashing your changes, including the untracked files, you can view the list of stashed entries using:

git stash list

This command will show you a list of all stashed changes. Each entry is indexed starting from stash@{0} for the most recent stash.

To reapply the changes you've stashed, use the git stash pop command. This command applies the stashed changes and removes them from the stash stack.

git stash pop

If you want to keep the stash in your stack, while still applying the changes locally, you can use git stash apply instead:

git stash apply

If you have multiple stashes, you can specify which stash to apply or pop by providing the stash identifier:

git stash apply stash@{0}

If you frequently use stashing, you may end up with multiple stashed entries. You can manage these individually by referring to their index in the stash list.

  • Dropping a stash: If you want to remove a specific stash from the stack:

    git stash drop stash@{0}
  • Clearing all stashes: If you decide you no longer need any of the stashed entries:

    git stash clear
  • Stashing specific files: If you want to stash only specific files (including untracked ones), you can specify them with the command:

    git stash push -u -- filename1 filename2
  • Handling merge conflicts: If applying a stash results in merge conflicts, you will need to resolve these conflicts manually. After resolving conflicts, complete the process by adding the resolved files to the index using git add, and then continue with your work. See this detailed guide on resolving merge conflicts for more info.

  • Using stashes for experiments: Stashes are great for trying out ideas without committing to the changes. If an experiment doesn’t work out, you can simply drop the stash.

For further reading on stashing in Git, see the official Git documentation.

Stay unblocked. Ship faster.
Experience the new developer workflow - create, review, and merge code continuously. Get started with one command.
Get started

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2