How to fix fatal: clean.requireForce defaults to true and neither -i, -n, nor -f given; refusing to clean in Git
Git refuses to run 'git clean' without a safety flag. This is an intentional safeguard to prevent accidental deletion of untracked files. Add -f, -n, or -i to proceed.
Quick fix
Fixes fatal: clean.requireForce defaults to true and neither -i, -n, nor -f given; refusing to clean
git clean -n- Preview files that would be removed with dry run
- Use force flag to remove untracked files
- Use interactive mode for selective cleaning
- Include untracked directories with -d flag
git clean -nfatal: clean.requireForce defaults to true and neither -i, -n, nor -f given; refusing to clean
What this error means
This error occurs when you run `git clean` without specifying one of the required safety flags. Git's `clean.requireForce` configuration defaults to `true`, which means Git will refuse to delete untracked files unless you explicitly confirm your intention. This is a safety feature, not a bug. The `git clean` command permanently removes untracked files from your working directory. Unlike tracked files, untracked files are not stored in Git's history, so once deleted, they cannot be recovered through Git. The requireForce setting ensures you don't accidentally delete important files like local configuration, generated assets, or work-in-progress code. The error message tells you exactly what flags you can use: `-i` for interactive mode, `-n` for a dry run (preview), or `-f` to force the deletion.
Typical symptoms
- Running 'git clean' without flags shows fatal error and refuses to run
- Attempting to remove untracked files fails with 'refusing to clean' message
- Scripts using 'git clean' fail in CI/CD pipelines
- Build automation fails when trying to clean workspace
- Error appears after upgrading Git or cloning a new repository
Common causes
- Running 'git clean' without any flags (the most common case)
- The clean.requireForce configuration is set to true (default behavior)
- Scripts or automation tools calling git clean without required flags
- Copy-pasted commands from outdated documentation missing the -f flag
- Misunderstanding that git clean requires explicit confirmation for safety
How to fix "fatal: clean.requireForce defaults to true and neither -i, -n, nor -f given; refusing to clean"
Before deleting anything, use the -n flag to see what would be removed:
git clean -nThis performs a "dry run" and lists all untracked files that would be deleted without actually removing them. Review this list carefully before proceeding.
Once you've verified the files to be removed, use the -f flag to proceed:
git clean -fThis will permanently delete all untracked files in the current directory and subdirectories. This action cannot be undone through Git.
For more control, use the -i flag to enter interactive mode:
git clean -iThis presents a menu where you can:
- Clean all files at once
- Filter by pattern to exclude certain files
- Select specific files by number
- Review each file individually before deletion
By default, git clean only removes untracked files, not directories. To also remove untracked directories:
# Dry run including directories
git clean -n -d
# Force remove files and directories
git clean -f -dBe especially careful with -d as it can remove entire folder structures.
To also remove files ignored by .gitignore:
# Remove untracked AND ignored files
git clean -f -x
# Remove ONLY ignored files (keep other untracked files)
git clean -f -XWarning: The -x flag will remove build artifacts, node_modules, IDE settings, and other ignored files. Use with caution.
Common flag combinations:
# Preview all untracked files and directories
git clean -n -d
# Remove all untracked files and directories
git clean -f -d
# Full reset: remove untracked and ignored files/directories
git clean -f -d -x
# Interactive mode with directories
git clean -i -dIf you want to clean untracked files but keep the option to recover them:
# Stash untracked files (can be recovered later)
git stash push --include-untracked -m "cleanup untracked files"
# Later, if you need them back:
git stash pop
# Or permanently remove the stash:
git stash dropThis is safer than git clean as files can be recovered from the stash.
Advanced notes
Disabling requireForce (not recommended): You can disable this safety check by setting:
git config --global clean.requireForce falseHowever, this is strongly discouraged as it increases the risk of accidentally deleting important files.
CI/CD considerations: In automated scripts, always use git clean -f explicitly rather than disabling requireForce. This makes the script's intent clear and maintains safety in interactive use.
Checking current configuration: To see if requireForce is explicitly set:
git config --get clean.requireForceIf nothing is returned, it defaults to true.
Excluding specific files: Use the -e flag to exclude files matching a pattern:
git clean -f -e "*.log" -e "config.local.json"Frequently asked questions
- What does "fatal: clean.requireForce defaults to true and neither -i, -n, nor -f" mean?
- This error occurs when you run git clean without specifying one of the required safety flags. requireForce configuration defaults to true, which means Git will refuse to delete untracked files unless you explicitly confirm your intention. This is a safety feature, not a bug.
- How do I fix "fatal: clean.requireForce defaults to true and neither -i, -n, nor -f"?
- Git refuses to run 'git clean' without a safety flag. This is an intentional safeguard to prevent accidental deletion of untracked files. Add -f, -n, or -i to proceed.
- What causes "fatal: clean.requireForce defaults to true and neither -i, -n, nor -f"?
- Running 'git clean' without any flags (the most common case) The clean.requireForce configuration is set to true (default behavior) Scripts or automation tools calling git clean without required flags
- Is the "fatal: clean.requireForce defaults to true and neither -i, -n, nor -f" error serious?
- It is a low-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Git Official Documentation
- ๐
- ๐ฌ
- ๐ฌ
- ๐ฌStack Overflow: where is clean requireforce set to true(Stack Overflow)
- ๐ฌ
- ๐
- ๐
- ๐
- ๐
- ๐