Name

clean

Synopsis

git clean -n|-f [-d] [-x]

Removes files from the work tree that are not in the Git index. By default, it only removes files that are not listed in .gitignore and does not remove directories. (To undo work tree changes to files that are in the index, use git checkout.)

You must provide one of -n or -f.

Options

-n (print only, do not remove)
-f (force removal of files)
-d (also remove extra directories)
-x (also remove files skipped by .gitignore)
-X (only remove files skipped by .gitignore)
-q (quiet)

Examples

To remove all extra files in the work tree so the only files remaining are ones that would be there after a fresh git clone:

$ git clean -f -d -x
Removing foo

To see what would happen if you ran the above command:

$ git clean -n -d -x
Would remove foo

Get Linux in a Nutshell, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.