๐ŸŽ“ A1Learner
๐Ÿ”
0 of 50 lessons completed

Clean Untracked Files

Clean deletes untracked files. It is how you clear scratch files you no longer want.

Look first

The safe look lists two scratch files.

$ git clean -n temp.txt temp2.txt

Delete them

The real run removes them both.

$ git clean -f temp.txt temp2.txt

They are gone

Only the gitignore file waits to be staged now.

$ git status --short

Example

$ git clean -n temp.txt temp2.txt
$ git clean -f temp.txt temp2.txt

Key points

  • Clean with -n only lists what it would delete.
  • Always run -n first. It is the safe look.
  • Clean with -f deletes the files for real.
  • Clean with file names deletes only those files.
  • Clean never touches tracked files.
  • Clean never touches ignored files.
  • There is no undo for clean. The files are gone.

Here, the look lists two files. The real run removes them both.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

What does git clean -n do?