git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC] git clean: add persistent exclude patterns

From
NJNicolas Jeanmonod <nicolas.jeanmonod@gmail.com>
Date
Sep 6, 2026, 13:56 UTC
Message-ID
<CA+35gGbO4_Yy=vZ+nZSLBorRnZMyBsr-Okn+rh0yrXiEWy=BFg@mail.gmail.com>
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

Message 1 of 1 in “[RFC] git clean: add persistent exclude patterns”
  1. Nicolas JeanmonodSep 6, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.