How to Remove Untracked Files From Local Git Working Tree

How to Remove Untracked Files From Local Git Working Tree

easier-docs-git-hero-image

The easiest way to do this is using the command git clean

To show what will be removed,

Run this command.

git clean -n -d

Running this command will list out all the untracked files and directories that will be removed.

To remove untracked files

git clean -f -d
⚠️
Warning! This will delete all the untracked files and directories from your git repo.

Also Remove files that are in your .gitignore

Running the previous command will only remove fies that are not in your .gitignore and untracked files. To also match and delete files that are included in your .gitignore, Use this command.

git clean -f -d -x

Interactively Remove files

git clean  -i

The -i here stands for interactive and it will prompt to you consider which file to be deleted.

Last updated on