Cleaning Up the Folder
Git clean.
Sometimes your folder fills up with junk. Test files, drafts, build output. None of it is tracked by Git. Git restore can't remove it, because Git doesn't know those files. For that, there's git clean.

- Junk files pile up
- Untracked, so restore can't help
- git clean removes them
Dry run first
Status shows three untracked things. A temp file, a draft, and a build folder. Always start git clean with dash n, which is a dry run. It only lists what would be removed. Add dash d to include folders. Nothing is deleted yet.
git status --short M index.html M style.css ?? build/ ?? draft.html ?? notes.tmp git clean -n -d Would remove build/ Would remove draft.html Would remove notes.tmp
Clean for real
Happy with the list? Then dash f, which means force, actually deletes them, and dash d includes folders. Status now shows only our tracked, modified files. The junk is gone.
git clean -f -d Removing build/ Removing draft.html Removing notes.tmp git status --short M index.html M style.css
Careful!
Git clean is permanent. The files were never committed, so Git can't bring them back, and they don't go to the trash. That's why you always run dash n first, and read the list carefully.
Summary
Git clean dash n shows what would be deleted, and dash f dash d deletes untracked files and folders. Next, resetting every tracked file at once.
Key takeaways- git clean -n -d
- git clean -f -d
- No undo