AI Hints
Home›Git & GitHub Tutorial›Cleaning Up the Folder
Git & GitHub · Lesson 36 of 144

Cleaning Up the Folder

Git clean.

⏱ 2 min read▶ Video at 38:51🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

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.

Cleaning Up the Folder
From the video: Cleaning Up the Folder
  • 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
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
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.

Permanentno undo
Not in historynever committed
-n firstdry run
-f -dforce, with folders

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
Next up: A Completely Fresh Start — restore everything