![]() |
VOOZH | about |
git clean remove untracked files and directories from the working directory to keep the repository clean.
Note: git clean is destructive and irreversible, so always use -n first to preview changes.
git clean provides multiple options to control how untracked and ignored files are removed, allowing safe previews, selective cleanup, and force deletion as needed.
Preview what will be deleted without actually removing anything.
git clean -nGit does not remove files unless explicitly forced.
git clean -fgit clean -fXgit clean -fxAllows selective deletion with user confirmation.
git clean -iBy default, directories are not removed.
git clean -fdThere are certain limitations associated which are as follows:
By default, it will not remove-
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"
Regular cleanup helps keep your Git repository synchronized, organized, and efficient.
Removes local references to deleted remote branches, keeping the repository in sync.
git remote prune <remote-name>Deletes local branches that have already been merged into the main branch.
git branch -d <branch-name>Removes unnecessary tags after merges or releases.
git tag -d <tag_name>
git push --delete origin <tag_name>
Deletes untracked files and directories from the working directory (use with caution).
git cleangit clean -fd is used to forcibly remove untracked directories along with untracked files from the working directory.
git clean -fdInteractive mode allows you to clean untracked files and directories with confirmation, reducing the risk of accidental deletion.
git clean --interactivegit clean permanently deletes untracked files, but it has specific technical limitations that must be considered.