# Handle untracked files that block checkout or merge

Canonical: https://githtml.com/guides/git-untracked-files-would-be-overwritten
Published: 2026-11-23
Publisher: WaveTech LLC / gitHtml

An untracked-overwrite warning means a local file that Git does not currently track occupies a path the incoming branch needs. Preserve that file outside the collision or in a verified stash that includes untracked files, then retry. Do not assume untracked means disposable, and do not run broad cleanup commands to silence the warning.

## Understand why the file is especially vulnerable

An untracked file may contain brand-new source, a manually prepared fixture, or a local export with no other copy. Git cannot recover it from ordinary commit history because it is not in that history. The target branch may legitimately track a different file at the same path, so overwriting blindly would destroy your local version.

Read the exact paths named in the error and compare their contents with the incoming versions when possible. A generated cache and a new test file deserve different decisions. Ignoring the path is not a preservation strategy: it can hide the warning context without saving the content. Likewise, deleting a whole directory may remove unrelated files that were never mentioned.

## Inventory and preserve the named files

Status with all untracked paths helps expose files hidden by directory summaries. Check-ignore explains whether another exclusion is involved. Choose a separate safe copy or a scoped stash with --include-untracked for the specific files. Verify the destination copy or saved entry before allowing the original path to be replaced.

1. If using stash, inspect the entry with --include-untracked so the saved new files are visible in the verification, not only tracked changes.
2. If moving a file aside, use an explicit reviewed destination and preserve its name and origin in a note so it can be compared after switching.

````shell
git status --short --untracked-files=all
git check-ignore -v -- path/to/file
git stash list
````

## Compare rather than blindly restore

Once the target branch is available, inspect its tracked version of the colliding path. Your saved local file may need to become a patch, a differently named fixture, or no change at all. Copying it back wholesale could overwrite legitimate incoming work. If stash application reports an existing untracked path or conflicts, stop and inspect instead of retrying with force. Finish with a clear account of which version was retained and where the other remains recoverable.

1. For a collision involving a directory, expand the inventory to individual files before moving anything. The incoming branch may track only one filename while the local directory contains several new assets. Preserve the complete relevant set, then compare the named collision separately from its unaffected neighbors.
2. After saving an untracked fixture, open the saved copy and check any companion files it requires. A JSON fixture and its binary attachment can form one useful unit even when Git names only the JSON path. Reintroduce that unit deliberately rather than treating a successful switch as recovery.

## Sources and further reading

- [Git reference: git-switch](https://git-scm.com/docs/git-switch)
- [Git reference: git-stash](https://git-scm.com/docs/git-stash)
- [Git reference: git-status](https://git-scm.com/docs/git-status)

## Related guides

- [Why a file in .gitignore still appears in Git changes](https://githtml.com/guides/gitignore-file-still-tracked)
- [Abort an unfinished Git merge carefully](https://githtml.com/guides/git-abort-merge-preserve-local-work)
- [Abort a Git rebase and verify the original branch](https://githtml.com/guides/git-abort-rebase-return-original-branch)
- [Fix Git’s “Author identity unknown” error](https://githtml.com/guides/git-author-identity-unknown-error)

Editorial approach: https://githtml.com/guides/about
