>_ IzzyLab

Hands-on task

This task is step 22 of the course “Git: rewriting and rescuing history”

Clean out only the ignored junk

medium~5 min

In /root/repo, junk has piled up after a build. There are tracked files (src.c, .gitignore), there are ignored build artifacts (app.o, cache.tmp, the build/ directory), and there are untracked but needed files that aren't in .gitignore (keep.txt, notes.md). Remove all the ignored junk from the working tree and only it: the tracked files and the untracked-but-needed ones must remain untouched.

What you'll practise:
  • git clean
  • untracked files
  • gitignore
  • dry run
  • cleaning the working tree

Topic breakdown

git clean removes untracked files from the working tree, but by default spares those that match .gitignore. The key point is the case of the scope flag: the lowercase variant wipes out all untracked files (including needed ones), while the uppercase one limits deletion to ignored artifacts only. It's complemented by the confirmation flag and the descend-into-subdirectories flag. Before actually deleting, it's worth running the command in dry-run mode (-n) to see the list of candidates and make sure needed files didn't end up in it.

What's checked

  1. ignored junk removed
  2. needed files preserved

What it looks like