

git clean -d -fīy default, git clean will only remove untracked files that are not ignored. Now run without -n if output was what you intend to remove. git subdirectory) unless a second -f is given. Git will refuse to modify untracked nested git repositories (directories with a. If the Git configuration variable clean.requireForce is not set to false, git clean will refuse to delete files or directories unless given -f or -i. If any paths are specified, -d is irrelevant all untracked files matching the specified paths (with exceptions for nested git directories mentioned under -force) will be removed. Specify -d to have it recurse into such directories as well. d Normally, when no is specified, git clean will not recurse into untracked directories to avoid removing too much. Always use -n firstĪlways use -n before running the clean command as it will show you what files would get removed. Use -f option twice if you really want toīe careful while running `git clean` command. Untracked directory is managed by a different Git repository, it is Remove untracked directories in addition to untracked files. This may be useful to rebuildĮverything from scratch, but keep manually created files.ĭon’t actually remove anything, just show what would be done. With git reset) to create a pristine working directory to test a clean This can be used (possibly in conjunction This allows removing all untracked files, gitignore (perĭirectory) and $GIT_DIR/info/exclude, but do still use the ignore If the Git configuration variable clean.requireForce is not set toįalse, git clean will refuse to run unless given -f, -n or -i.ĭon’t use the standard ignore rules read from. If clean.requireForce is set to "true" (the default) in your configuration, one needs to specify -f otherwise nothing will actually happen.Īgain see the git-clean docs for more information. Note the case difference on the X for the two latter commands. To remove ignored and non-ignored files, run git clean -f -x or git clean -fx.To remove ignored files, run git clean -f -X or git clean -fX.To remove directories, run git clean -f -d or git clean -fd.Step 1 is to show what will be deleted by using the -n option: # Print out the list of files and directories which will be removed (dry run)Ĭlean Step - beware: this will delete files: # Delete the files from the repository

arguments are given, only those paths are affected. This can, for example, be useful to remove all build products. Normally, only files unknown to Git are removed, but if the -x option is specified, ignored files are also removed. The -raw output used to be obtained by git whatchanged, back in the early days of Git, and it's actually still one of the styles I prefer.Git-clean - Remove untracked files from the working tree Synopsis git clean …Ĭleans the working tree by recursively removing files that are not under version control, starting from the current directory. It won't hurt to check, but usually it's easier to check with git log -name-status or git log -raw. If you have not been deliberately adjusting Git's index as you work, though, the fact that they're not in the index now is usually enough of an indicator that you don't need to check. (You can inspect the complete set of files in any given commit using git ls-tree -r: supply an identifier for that commit, e.g., a branch name like master, or a branch name with a relative suffix, like master~2, or a raw hash ID.

So if those files aren't in Git's index now, they probably weren't in Git's index earlier, and hence will not be in any earlier-made commits either. Git makes new commits from its index, not from your work-tree. Commits of course contain files, so whatever files are in the commits that go in, are in-but an untracked file is by definition a file that is not currently in Git's index. The git push command pushes commits, not files.
