How to fix fatal: clean.requireForce defaults to true and neither -i, -n, nor -f given; refusing to clean in Git

GitBEGINNERLOWUpdated Dec 6, 2025ยท 155 views

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
  1. Preview files that would be removed with dry run
  2. Use force flag to remove untracked files
  3. Use interactive mode for selective cleaning
  4. Include untracked directories with -d flag
git โ€” error
git clean -n
fatal: 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

  1. Running 'git clean' without any flags (the most common case)
  2. The clean.requireForce configuration is set to true (default behavior)
  3. Scripts or automation tools calling git clean without required flags
  4. Copy-pasted commands from outdated documentation missing the -f flag
  5. 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"

1Preview files that would be removed with dry run

Before deleting anything, use the -n flag to see what would be removed:

bash
git clean -n

This performs a "dry run" and lists all untracked files that would be deleted without actually removing them. Review this list carefully before proceeding.

2Use force flag to remove untracked files

Once you've verified the files to be removed, use the -f flag to proceed:

bash
git clean -f

This will permanently delete all untracked files in the current directory and subdirectories. This action cannot be undone through Git.

3Use interactive mode for selective cleaning

For more control, use the -i flag to enter interactive mode:

bash
git clean -i

This 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

4Include untracked directories with -d flag

By default, git clean only removes untracked files, not directories. To also remove untracked directories:

bash
# Dry run including directories
git clean -n -d

# Force remove files and directories
git clean -f -d

Be especially careful with -d as it can remove entire folder structures.

5Remove ignored files with -x or -X flags

To also remove files ignored by .gitignore:

bash
# Remove untracked AND ignored files
git clean -f -x

# Remove ONLY ignored files (keep other untracked files)
git clean -f -X

Warning: The -x flag will remove build artifacts, node_modules, IDE settings, and other ignored files. Use with caution.

6Combine flags for common workflows

Common flag combinations:

bash
# 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 -d
7Alternative: Use git stash for recoverable cleanup

If you want to clean untracked files but keep the option to recover them:

bash
# 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 drop

This 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:

bash
git config --global clean.requireForce false

However, 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:

bash
git config --get clean.requireForce

If nothing is returned, it defaults to true.

Excluding specific files: Use the -e flag to exclude files matching a pattern:

bash
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