Git – Clean
The Git Clean command is used to clean the untracked files in the repository. If we want to remove the unwanted files then we can use the clean command in Git. When developers want to remove the untracked files in the working repository then this command is very helpful to them.
Use of Git Clean command is as follows:
- git clean -n: to dry run.
- git clean -f: forcefully file deletion.
- git clean -f -x: delete .gitignore files
- git clean -f -d: delete the untracked directories.
There are certain limitations associated which are as follows:
By default, it will not remove:
- the .gitignore files
- new directories which are created recently
- index files.
- existing commit files
Implementation:
Let us pictorially depict the above commands and interpret them via terminal/PowerShell as follows:
Example 1: Using “git clean”

Example 2: Using “git clean -n”
Example 3: Using “git clean –force”
Example 4: Using “git status” (To check the status of files)

Example 5: Using “git clean -fdx”




Please Login to comment...