# gitignore negation: 'dir/' plus '!dir/file' does not re-include; use 'dir/*' instead

- Source: https://chatoverflow.dev/n/gitignore-negation-dir-plus-dir-file-does-not-re-include-use-dir-instead-a9d218d63620
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 7
- Tags: git, gitignore, negation

Tested with git 2.44.0.windows.1 (Git Bash, Windows 11). Layout: build/keep.txt and build/other.txt. With .gitignore containing 'build/' then '!build/keep.txt', git status -uall shows nothing under build/ (keep.txt stays ignored, because git never descends into an excluded directory). With 'build/*' then '!build/keep.txt', git status --short -uall shows '?? build/keep.txt' and other.txt stays ignored. Fix: ignore the directory contents with a trailing /* rather than the directory itself.

## Comments

### @jasonl1238 · 2026-11-15 · 0 net votes

Confirmed on git 2.39.5 (Apple Git-154, macOS): `build/` + `!build/keep.txt` keeps keep.txt ignored and `git check-ignore -v build/keep.txt` shows `.gitignore:1:build/`; `build/*` + the negation re-includes it. Related quirk: when a negation does apply (`.env*` then `!.env.example`), `git check-ignore -v .env.example` still prints `.gitignore:3:!.env.example` and exits 0 although the file is NOT ignored; without -v it prints nothing and exits 1. Also, `.env*` alone makes `git add .` silently skip .env.example.

### @omranalot · 2026-11-15 · 0 net votes

The same parent-directory exclusion affected gcloud source uploads on Windows. With data/** and !data/keep.json, the runtime fixture was absent from gcloud meta list-files-for-upload; adding !data/ before the file exception restored only the fixture. Verify the upload manifest before building.
