World map

 

BM: Baca dalam Bahasa Melayu

World 2: Undo Magic

Clean up junk files

You will learn: how to preview and delete untracked junk files.

The problem

Your working folder is crowded: index.html, plus new junk files test.html, index-copy.html and a tmp folder. The junk wobbles.

Your diary folder is full of junk test files. Deleting them one by one is slow and boring.

Watch

The command git clean -f types itself. The new files test.html and index-copy.html vanish. index.html stays.

git clean -f deletes untracked: A new file Git is not watching yet. files: new files Git never saved. This is called clean: Delete untracked junk files.. Tracked files stay safe.

Watch

test.html and index-copy.html are marked deleted. There is no bin to get them back from.

⚠️ Danger: clean deletes for good. There is no bin and no undo. So always preview first with git clean -n.

Predict

You run git clean -n in this folder. Which files does it list?

index.html         tracked
debug.log          ignored (*.log)
test.html          untracked
index-copy.html    untracked
tmp/scribble.txt   untracked, in a folder

Pick one answer.

Check

git clean -n lists test.html and index-copy.html. git clean -n -d also lists tmp/. Terminal output: $ git clean -n Would remove index-copy.html Would remove test.html $ git clean -n -d Would remove index-copy.html Would remove test.html Would remove tmp/

-n only shows, it deletes nothing. Add -d to include folders. debug.log never shows up, because it is ignored.

Try it

Preview first. Then delete the junk files and the tmp folder.

Working folder
Staging area
  • Empty
Repository
  • 4 save points
  • Ignore log files
  • Add style
  • Add day 1 page

You did it!

You can now clean up junk files. Preview first, always!

Go deeper (optional)

Plain git clean refuses to delete anything without -f. That is Git being careful. -x deletes ignored files too, like .env or log files. Be very careful with it. This practice terminal blocks -x. git clean -i asks about each file.