How to remove local files from the current Git working tree
Explanation
git-clean – It is used to remove local files which are untracked files that are present in the working tree
Synopsis
git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>…
Here we have the Description
So it is used to refresh the working tree by continuously removing files. Files that are not in the control of the version. Also, it will start working from the directory that is in the work mode.
Generally, files which are not known to Git are clean or removed. In case if we specify the option -x
, so at that time that files are also removed which we have ignored. Also, this is very useful if we want to remove all build products.
So that if we have any optional <path>...
arguments are given. At that time only specific paths will get affected.
Next is to show that what is going to delete by using the -n
option:
# Print out the list of files and directories which will be removed (dry run)
git clean -n -d
Clean Step – beware: this will delete files:
# Delete the files from the repository
git clean -f
-
- So if we want to remove directories, at that time run
git clean -f -d
orgit clean -fd
- And if we want to remove ignored files, use run
git clean -f -X
orgit clean -fX
- So in last to remove ignored and non-ignored files, use run
git clean -f -x
orgit clean -fx
- So if we want to remove directories, at that time run
And if clean.requireForce
is set to default i.e. true in the configuration. At that time we have to use -f
. If we don’t use this nothing will happen in the git.
Also, see the git-clean
docs for more information.
Options
-f
, --force
This is used when the Git configuration variable is clean.requireForce is not set to false. So at that time git clean will not run unless given -f
, -n
or -i
.
-X
This is used when we want to remove local files which we ignore earlier. Also if we want to rebuild everything from scratch.
-d
Remove untracked directories in addition to untracked files. If an untracked directory is managed by a different Git repository, it is not removed by default. Use -f
option twice if you really want to remove such a directory.
So, this is how we remove local files from the current Git working tree
Also, read, How do I check if an element is hidden in jQuery?