Git cannot restore untracked files that were never added to the repository, because Git never stored their contents. If your files were untracked and something deleted them, Git's own recovery tools can only help if you had staged them at some point—git fsck --lost-found can sometimes recover staged-but-committed-never blobs—or if the "deletion" was actually a file that exists somewhere else, such as a stash, another branch, or your editor's local history. The first step is therefore to pin down what actually happened, because the recovery path differs sharply depending on whether the files were merely hidden by Git, deleted from disk, or replaced by a checkout.

The confusion behind the search phrase usually comes from conflating two situations: files that are untracked in the working tree (Git knows they exist but ignores them) and files that were deleted and need to be brought back. Understanding Git's object model makes clear why the answer has hard limits.

What "untracked" actually means

A file is untracked when it exists in the working directory but is not in the index (the staging area) and not in the current commit. Git is aware of the file's existence only enough to report it in git status and to avoid overwriting it in most operations. It has not hashed the file's contents into the object database, so there is no stored blob to check out.

This is the crucial asymmetry: tracked files are recoverable because their contents live in commits (and in the reflog, dangling commits, and the object database). Untracked files live only on your filesystem. Git provides no history, no backup, and no undo for them.

That said, several legitimate situations produce a request like "restore all untracked files," and each has a workable approach.

Situation 1: You want the untracked files to appear as they were before a checkout or merge

If you ran git checkout, git switch, git reset --hard, or git merge and afterward found untracked files missing, the most common cause is that the operation clobbered files whose paths collided with tracked content coming in. Git will normally refuse to overwrite an untracked file during checkout; it aborts with an error like "The following untracked working tree files would be overwritten by checkout." If you forced the operation with -f, or if a tool or script removed files, the contents are gone from Git's perspective.

There is one real recovery avenue here: if the files had been staged at any point, their blob objects may still exist in .git/objects even after being unstaged or after a reset removed them from the index. The command

scans for dangling and unreachable objects and writes dangling blobs into .git/lost-found/other/. You can then inspect those files' contents (they are stored without their original filenames) and match them back. This works only for content that was added to the index at least once, because git add is what creates the blob. Truly never-staged files are not recoverable this way.

For future protection, git stash push --include-untracked (or -u) stashes untracked files alongside tracked changes, and git stash pop brings them back. Many people discover this command only after losing work; it is worth adopting as a habit before any destructive operation.

Situation 2: Untracked files exist but git status stopped listing them

Sometimes nothing was lost—Git just stopped showing files. The usual culprit is .gitignore. A pattern added to .gitignore, .git/info/exclude, or a global excludes file can make previously listed files appear to vanish from git status while they remain untouched on disk. Check with:

or ask Git directly why a specific path is ignored:

The -v flag prints the exact file and line number of the matching pattern. Another possibility is that files were removed from the index with git rm --cached, which turns tracked files into untracked ones without deleting them. And a change of directory, worktree, or branch can change which files Git considers relevant. In all these cases, "restoring" simply means adjusting ignore rules or re-adding files with git add.

Situation 3: Files were deleted from the working tree

If untracked files were deleted by rm, a failed script, or an editor, Git cannot help unless they had been staged. Look first in the obvious non-Git places: your operating system's trash or recycle bin, your editor's local history (VS Code keeps a timeline, JetBrains IDEs keep local history, Vim keeps swap and undo files), and any file-sync service such as Dropbox, OneDrive, or Time Machine backups.

If the files were staged before deletion, git fsck --lost-found is again the tool. Note that Git's garbage collection (git gc) eventually prunes unreachable objects, so recovery chances decline with time and with commands that aggressively prune. Running git fsck early matters.

What does not work, and why people think it does

A frequent misconception is that git checkout -- . or git restore . will bring back untracked files. It will not. These commands restore tracked files from the index or a commit; untracked files are outside their scope, and in many Git versions git restore . will simply report nothing to do for them. Similarly, git reset --hard discards tracked changes and does not resurrect untracked files—in fact, it is one of the operations most likely to be running when people notice missing files, though it does not itself delete untracked files unless they collide with tracked paths during a subsequent checkout.

Another misconception: the reflog. The reflog records movements of branch tips (commits), not working-tree state. It is invaluable for recovering committed work after a bad reset or rebase, but it has nothing to say about files that were never committed.

Recovering commits that contain the files, if they were ever committed elsewhere

If the files were tracked on another branch, in another worktree, or in a stash, they are recoverable by checking out that ref. Useful commands:

git stash list, then git stash show -p stash@{n} to inspect, and git checkout stash@{n} -- path (or git restore --source=stash@{n} path) to extract specific files. git branch --all and git log --all -- path/to/file to find commits on any branch that touched the path. git log --diff-filter=D --summary to find commits that deleted files, which can be restored from the parent commit with git checkout ^ -- path.

If the path appears in git log --all, it was tracked at some point, and the content is in the object database. That is a fundamentally different and much better situation than a file that was never added.

A practical decision sequence

When you sit down to recover, work through these questions in order. First, is the file still on disk? Run ls or your file manager before anything else, and check git status --ignored. Second, was it ever staged? If you are unsure, git fsck --lost-found is cheap and non-destructive. Third, does any ref—branch, stash, tag, or remote-tracking branch—contain the path? git log --all -- answers this. Fourth, check editor history and OS-level backups. Only after all four fail should you conclude the content is unrecoverable.

Situation Recovery method Chances
File exists but hidden from status Fix .gitignore, use git status --ignored Certain
Was staged, then deleted git fsck --lost-found Good if not yet pruned
Tracked on another branch or stash git checkout -- path Certain
Committed then deleted Restore from parent commit Certain
Never staged, deleted from disk Editor history, trash, backups only Depends on outside tools

Preventing the problem

The durable fix is to stop treating untracked files as safe. Files you care about should be committed or at least stashed. For scratch work and generated files, commit them to a throwaway branch or use git stash -u before risky operations. Before any checkout, reset --hard, clean, or merge, run git status and read the untracked section; git clean -n (dry run) shows what git clean -f would delete, and untracked files removed by git clean are not recoverable through Git at all.

It also helps to commit early and often, even imperfectly. A commit costs almost nothing and converts an unrecoverable file into a fully recoverable one. The distinction between "untracked" and "tracked but uncommitted" is small in effort and enormous in consequence.

The short version

Git can restore tracked content from commits, the index, stashes, and dangling objects; it cannot restore files it never stored. For untracked files, recovery depends on whether they were ever staged (use git fsck --lost-found), whether they exist in another ref (use git checkout -- path), or whether they were merely hidden by ignore rules (use git status --ignored and git check-ignore -v). If none of those apply, the contents were never in Git, and your only recourse is editor history, the operating system's trash, or backups. The reliable long-term answer to "how can all untracked files be restored" is to make sure the important ones stop being untracked.