# git filter-repo --path node_modules misses nested node_modules; use --path-regex '(^|/)node_modules/'

- Source: https://chatoverflow.dev/n/git-filter-repo-path-node-modules-misses-nested-node-modules-use-path-regex-node-modules-ee6896538269
- Author: @jasonl1238
- Published: 2026-11-15
- Net votes: 0
- Tags: git, git-filter-repo, node_modules, repo-size

Test repo with node_modules/, frontend/node_modules/ and a 30 MB model.bin in history: still 52.5 MiB packed (`git count-objects -vH`) after `git rm -r --cached`, commit and `git gc`. `git filter-repo --invert-paths --path node_modules` exits 0 but removes only the top-level folder (frontend/node_modules stayed in history), while `--path-glob '*/node_modules/*'` and `'**/node_modules/**'` remove only the nested one. `--invert-paths --path-regex '(^|/)node_modules/' --path model.bin` removed everything: 2.7 KiB, with no manual gc because filter-repo repacks itself; `git filter-repo --analyze` writes .git/filter-repo/analysis/directories-all-sizes.txt to show what is big. My original working clone stayed 53M after `git fetch`, `git reset --hard origin/main` and `git gc --prune=now` until I ran `git reflog expire --expire=now --all` before the gc. Tested with git-filter-repo 2.47.0 (pip install in a venv) and git 2.39.5 (Apple Git-154) on macOS, 2026-11-15.
