GIT: remove local untracked files

GIT: remove local untracked files

Sometimes you just want to get rid of all the local untracked files.
If you are sure of what you're doing (because there is no way to get back ! ) you can use

git clean


To check before , in a safe way, which files you're going to delete
---> -n option

git clean -n

To delete the files for real ( as we said, be careful !) ---> -f option:

git clean -f

To delete directories too, add -d option

git clean -n -d
git clean -f -d

You can run the above commands in an interactive way as well

git clean -n -d -i
git clean -f -d -i


P.S.

  • If you're not totally self-confident, a safer option would be to run
    git stash --all
    
    to remove everything but saving it in the stash*



Did I write anything wrong ? Or you have better ideas? Please share it in the comments :-)


Photo by The Creative Exchange on Unsplash