Including Untracked Files
By default, git stash
ignores untracked files. To include untracked files in your stash, you need to use the --include-untracked
option (or -u
for short). This option tells Git to stash not only the changes to tracked files but also any untracked files.
git stash -u
Example 1:
Implementation to stash both tracked and untracked files using the -u option.
Step 1: You have untracked files in your working directory.
Step 2: Run the git stash -u command to stash changes.
Step 3: Check the status to confirm the stash.
How to Stash an Untracked File in Git?
Stashing is a powerful feature in Git that allows developers to save their current work and switch contexts without committing to the repository. By default, Git’s stash command only saves tracked files. However, there are situations when you might need to stash untracked files as well. This article will guide you through the process of stashing untracked files in Git.
Contact Us