Untracked files are handled separately from modifications, and git clean is the dedicated tool for removing them. By default it removes untracked files; adding -d extends it to untracked directories. A dry run with git clean -nd lists everything that would be deleted without touching the disk, which is the safest way to preview before running the real git clean -fd. Forgetting to clean untracked files leads to a common two-step cleanup: git restore . clears modifications in tracked files, and git clean -fd then sweeps up anything untracked that remains. Because git clean operates on files Git has never recorded, it is genuinely destructive and cannot be undone by Git itself.
Sometimes a .gitignore rule refuses to take effect because the offending file is already tracked by Git. The fix is git rm --cached path, which removes the file from the index (and from the next commit) without deleting it from your working tree; commit the removal and the ignore rule will start working. To see exactly which rule is being applied to a path, use git check-ignore -v path, and to see everything Git is currently ignoring, add --ignored to git status. Note that Git cannot track empty directories at all, so the convention is to commit a placeholder such as .gitkeep whenever a folder's presence needs to be preserved across checkouts.