How do you delete untracked local files from your current working tree?
Always use -n
before running the actual command as it will show you what files would get removed.
git clean -n -d
git clean -f -d
By default, git clean
will only remove untracked files that are not ignored. Any file that matches a pattern in your .gitignore or other ignore files will not be removed. If you want to remove those files too, you can add a -x
to the clean command.
git clean -f -d -x
There is also interactive mode available -i
with the clean command
git clean -x -i
If you are not 100% sure that deleting your uncommitted work is safe, you could use stashing instead
git stash --all
It will also clear your directory but give you flexibility to retrieve the files at any point in time using stash with apply or pop. Then at later point you could clear your stash using:
git stash drop // or clean