threads / rfc / 66280

[RFC] git clean: add persistent exclude patterns

Subject: [RFC] git clean: add persistent exclude patterns

## tl;dr

One message between Sep 6, 2026 and Sep 6, 2026.

replies: 0people: 1as markdown or json

Nicolas Jeanmonod· Sep 6, 2026, 13:56 UTC · lore
Hi,

I would like to propose a way to configure persistent exclusion patterns for `git clean`.

Currently, `git clean` supports:

``` -e <pattern> --exclude=<pattern> ```

and these exclusions are deliberately still honored when `-x` is used.
For example:

``` git clean -fdx -e '*nogitclean*' ```

will remove ignored files while preserving paths matching `*nogitclean*`.

What seems to be missing is a way to make such exclusions persistent. A possible configuration could be:

```
[clean]
    exclude = *nogitclean*
```
or, for multiple patterns:
```
[clean]
    exclude = *nogitclean*
    exclude = important-local-data/
```
which could be configured globally or per repository:

``` git config --global --add clean.exclude '*nogitclean*' ```

The intended semantics would be the same as if the configured patterns had been supplied using `git clean -e`: in particular, they would continue to protect matching paths when `git clean -x` is used.

The use case is slightly different from `.gitignore` or `core.excludesFile`. Those answer the question "which files should Git normally ignore?", whereas this configuration would answer "which untracked paths should `git clean` never remove by default, even when cleaning ignored files?"

One concrete use case is keeping local metadata or other irreplaceable directories inside a working tree while still being able to use `git clean -fdx` for build products. Such directories may intentionally be ignored by Git, but `-x` currently removes them unless the corresponding `-e` option is remembered every time.

An alternative design could be a dedicated file such as `clean.excludesFile`, but a multi-valued `clean.exclude` setting seems simpler and maps directly to the existing `-e` option.

Would such a configuration be considered useful and consistent with the intended semantics of `git clean`?

Thanks, Nicolas

← back to recent threads