I hope that, you are finding my posts on Git Basics/Git Tutorial helpful. In the last post on this series, we learned "How to stash the changes in a dirty working directory?". Today we are going to discuss how to remove untracked files.
Everyone needs to clean the working tree when some job is done or want to reset the directory. Let's learn how to do this using the command "git clean".
The command "git clean" cleans the working tree by recursively removing files that are not under the version control. It starts the cleanup from the current directory. In case you want to shelve your dirty directory before cleaning, read out the "git stash" command.
In general, only the files unknown to Git are removed, but if you specify the '-x' option, the ignored files are also removed. When you specify '-d', the untracked directories also get cleaned in addition to the untracked files. You can combine all the parameters together to have a clean working set of the files and directories.
Here is the list of command parameters, which you will find useful while working with Git repositories to clean the current working tree.
$ git clean
$ git clean -d
$ git clean -f
$ git clean --force
$ git clean -i
$ git clean --interactive
$ git clean -x
$ git clean -X
$ git clean -xfd
$ git clean -x -f -d
Was this post useful? If you came to this page by searching online about “git basics” or “git tutorials”, please have a look into my other blog posts. Subscribe to the RSS feed or the email newsletter to keep yourself updated.