Folder ignored with a trailing slash
- Input
- build/ + !build/keep.txt → build/keep.txt
- Expected output
- ignorado pela linha 1 / ignored by line 1
The negation on line 2 has no effect.
gitignore ignore folder except one file
Type the rules in the Test tab and paste the paths: the result says whether the negation took effect or was blocked by the parent folder, with the responsible line.
The negation on line 2 has no effect.
Line 2 re-includes the file.
Only keep.txt was re-included.
build/out is excluded by build/*.
Each folder along the path must be re-included.
The rest of uploads/ stays ignored.
Tap the shortcut for your stack (Next.js, Python, Laravel, Unity and others) or search by name: react and vite open the Node template, django opens Python. Add the editor (Visual Studio Code, JetBrains) and the operating system (macOS, Windows, Linux) of the people working on the project, copy the result and save it as .gitignore at the repository root. Editor and OS templates can also go to a global file (core.excludesFile) so they do not clutter the project.
Because folder/ excludes the directory and Git does not descend into an excluded directory. Switch to folder/* to ignore only the contents so the negation applies.
No. It is just a convention. Any committed file inside the folder makes Git create it on clone; what matters is that the negation rule points to the name you chose.
Yes. The last matching rule wins. The negation must come after the rule that ignores, which is why !build/keep.txt before build/* would have no effect at all.
Loading templates...
Pick at least one template to generate the file.
Loading templates...
# Normalize line endings: Git detects text files, LF in the repository. * text=auto eol=lf # Shell scripts need LF; Windows scripts need CRLF. *.sh text eol=lf *.bat text eol=crlf *.cmd text eol=crlf *.ps1 text eol=crlf # Binary files: no conversion and no text diff. *.png binary *.jpg binary *.jpeg binary *.gif binary *.ico binary *.webp binary *.pdf binary *.zip binary *.gz binary *.woff binary *.woff2 binary # Lock files: GitHub collapses them in diffs. package-lock.json linguist-generated yarn.lock linguist-generated pnpm-lock.yaml linguist-generated
.gitignore only applies to files Git does not track yet. To stop tracking without deleting from disk:
git rm --cached path/to/file git rm -r --cached path/to/folder git commit -m "Stop tracking ignored files"
To re-apply the .gitignore to everything at once (review git status before committing):
git rm -r --cached . git add . git commit -m "Apply .gitignore"
To ignore only on your machine, use a global file (core.excludesFile) or the clone's .git/info/exclude, with the same syntax:
git config --global core.excludesFile ~/.gitignore_global .git/info/exclude
No problems found in the rules.