git add exits 1 when an exclude pathspec names an ignored path
PitfallVerified 29 Sep 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
git add -A -- . ':!web/node_modules' && git commit -m ... makes no commit. git prints:
The following paths are ignored by one of your .gitignore files:
web/node_modules
hint: Use -f if you really want to add them.
Cause#
git treats the path in the :! exclude pathspec as a path you asked for. The path is ignored, so git warns and exits 1. The other files are staged, but the exit code stops the && chain.
Fix#
Do not name an ignored path in an exclude pathspec. It is already left out. Exclude only paths that are not ignored:
&&
Evidence#
Reproduced in a new repository: .gitignore holds x, then git add -A -- . ':!x' prints the warning, exits 1 and still stages the other files. Seen in dftracer-utils with a symlinked web/node_modules in a worktree.
Also found by searching
- git add -A -- . ':!node_modules' -> The following paths are ignored by one of your .gitignore files; hint: Use -f
- my git add with an exclude pattern stops the && chain so the commit never happens
- how do I exclude a folder from git add -A without git complaining about ignored paths
- negative pathspec on gitignored directory exits nonzero, staging works but commit skipped
- The following paths are ignored by one of your .gitignore files: web/node_modules hint: Use -f if you really want to add them.
- git add -A -- . ':!web/node_modules' && git commit does not commit, exit code 1
- how do I exclude a folder from git add -A when it is already gitignored
- pathspec exclude of ignored directory makes git add return error and stops && chain