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.txtDelete them
The real run removes them both.
$ git clean -f temp.txt temp2.txtThey are gone
Only the gitignore file waits to be staged now.
$ git status --shortExample
$ git clean -n temp.txt temp2.txt
$ git clean -f temp.txt temp2.txtKey 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?