The Wayback Machine - https://web.archive.org/web/20230410152046/https://www.geeksforgeeks.org/git-clean/
Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Git – Clean

Improve Article
Save Article
Like Article
  • Difficulty Level : Expert
  • Last Updated : 16 Feb, 2022
Improve Article
Save Article
Like Article

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”

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles