The quick answer
A .gitignore lists the files Git must never track: node_modules/, dist/, .DS_Store and the .env family that holds your secrets. This generator merges 12 curated sections covering 47 patterns (stacks, operating systems, editors, secrets) into one annotated file, entirely in your browser. Nothing uploads.
The 900 MB repository
A repository with a missing or half-written .gitignore grows in exactly one direction, because Git tracks whatever you tell it to track. Every machine that touches the repo contributes droppings: node_modules from an old commit, .DS_Store from every macOS contributor, a backup/ directory holding three previous versions of the project and, worst case, a .env with production keys. None of that is Git's fault; the repo was simply missing its .gitignore, or had a badly wrong one. The file itself is a few lines of pattern syntax naming what never to track: dependency caches, build output, OS junk, editor scratch state, and the .env files that hold your secrets.
The .gitignore Generator on this page takes 12 section toggles (languages, operating systems, editors, secrets) and merges curated templates into one file, with a # comment naming each block's purpose. It runs entirely in the browser, covers the .env family by default, and takes an Extra patterns box for anything its sections miss. This article covers the pattern grammar, the negation trap, the leaked-key timeline, and the recovery path for a repository that is already bloated.
Assembling a .gitignore that matches your stack
Check your stack
Node, Python, Docker, Next.js and friends. Each adds that stack's dependency directories, build outputs and tool caches: the files that are reproducible from source and therefore never belong in history.
Add your operating systems
macOS contributes .DS_Store, .AppleDouble, .Spotlight-V100 and .Trashes; Windows contributes Thumbs.db, Desktop.ini and $RECYCLE.BIN/; Linux adds *~, .fuse_hidden* and .directory. Everyone who clones the repo benefits, because junk arrives with every contributor's laptop, not just yours.
Add your editors
Two IDE sections. The VS Code section demonstrates the keep-shared-settings strategy (ignore .vscode/*, re-include settings.json and extensions.json); the JetBrains section ignores .idea/ and *.iml outright. See the .vscode question in the FAQ below.
Toggle the Env & secrets section
The .env family (.env, .env.local, .env.*.local) plus key and certificate files (*.pem, *.key) and one deliberate exception, !*.key.example. On by default, because an ignored secret is infinitely preferable to a committed one.
Review the merged template
The output arrives with a # comment naming each block and its purpose, and the Extra patterns box underneath takes anything the sections don't cover, one pattern per line (its own placeholder suggests data/*.csv with a !data/sample.csv exception). Delete blocks you know you don't need; a lean .gitignore is easier to audit than a kitchen-sink one.
Copy into your repository root
The Copy .gitignore button puts the file on your clipboard; save it as .gitignore at the repo root, commit it, and verify with git status that your build directories went dark. If something still shows up that shouldn't, the pattern-semantics section below will tell you why.
Pattern semantics, minus the folklore
Git's ignore language is small, and most of its confusion comes from three characters: the slash, the star, and the exclamation point. Here is the whole grammar that matters in practice.
| Pattern | Matches | Notes |
|---|---|---|
| node_modules/ | Any directory named node_modules, at any depth | Trailing slash means directories only, contents included |
| dist | File or directory named dist, anywhere | No slash = unanchored, matches at every level |
| /dist | Only the dist at the .gitignore's own level | Leading slash anchors the pattern |
| *.log | Every file ending .log, everywhere | Classic wildcard form |
| build/* | Everything inside build, but not build itself | The wildcard that makes re-inclusion possible |
| !keep.me | Do not ignore keep.me | Negation; see the parent-directory trap |
| **/temp | temp at any depth | Double star crosses directory boundaries |
| doc/**/notes | notes anywhere under doc | Double star in the middle works too |
Two rules do the most damage when missed. First, the last matching pattern wins: order matters, and a negation placed above the rule it opposes is simply dead text. Second, Git does not descend into ignored directories, so you cannot re-include a file whose parent directory is excluded. `build/` followed by `!build/keep.txt` silently fails; `build/*` followed by `!build/keep.txt` works, because with the wildcard form the directory itself was never excluded, only its contents. This asymmetry is a perennial Stack Overflow question, and it has an entry in the FAQ below.
And one rule that outranks all of them: .gitignore affects only untracked files. If Git is already tracking a file, no pattern will untrack it. The fix is `git rm --cached <file>` followed by a commit; --cached removes it from the index while leaving your working copy alone. When a whole directory needs untracking, `git rm -r --cached <dir>` does it in one stroke, and the newly-ignored files vanish from every future diff. To debug which rule matches a given path, `git check-ignore -v <path>` prints the exact file, line, and pattern responsible: the underused command that turns ignore debugging from divination into lookup.
One merged template, annotated block by block
The generator ships with Node, the VS Code section, Env & secrets and macOS pre-checked, so the first render already covers the common web-service case: 21 patterns in four blocks. Here is that default output with the patterns exactly as the tool writes them, minus the comment lines it prefixes to each block.
# Generated by Toolzep's .gitignore builder
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.npm
dist/
build/
.cache/
.DS_Store
.AppleDouble
.Spotlight-V100
.Trashes
.vscode/*
!.vscode/settings.json
!.vscode/extensions.json
.env
.env.local
.env.*.local
*.pem
*.key
!*.key.exampleIn the real file, each block opens with a # comment carrying the section name and a one-line purpose: npm/yarn/pnpm + build output for Node, Finder metadata for macOS, keep shared settings, drop the rest for VS Code, and the files that must never be committed for Env & secrets. The first line names the tool that built the file, which makes generator-authored .gitignores easy to spot in the wild.
Read the .env block carefully, because it encodes a modern convention. The .env.*.local pattern catches the environment-specific variants that frameworks like Next.js and Vite generate and document: the files that hold the real secrets for local development, staging, and production. The committed companion file, .env.example, lists the same keys with placeholder values, so new contributors learn what configuration exists without learning your database password. Ignored secrets are a speed bump, committed secrets are an incident; and if a secret ever reaches history, rotation is the only real remedy, because history is forever.
The .vscode block demonstrates the re-inclusion pattern from the semantics section in its practical form: ignore the whole directory with a wildcard, then negate the two files teams actually share. Extensions lists and shared formatting settings travel with the repo; everything personal stays local. That is the difference between a template that says "ignore .vscode" and one that says why, and which files to carve back out.
Anatomy of a leaked key: what happens in the first hour
Minute zero: rotate first, clean second
The instinct is to delete the file from the repo. The priority is the opposite: revoke or rotate the credential at its provider, deactivating the AWS key, regenerating the database password, reissuing the API token. Removal stops future pushes; rotation stops the copy already in history, in every clone, and in every crawler's index.
Minute five: untrack and commit
git rm --cached .env removes the file from the index while keeping the local copy, and the .gitignore rule you should already have prevents re-adding it. Push the fix so teammates' clones stop carrying the file forward.
Minute thirty: rewrite history if the repo is shared
The old commits still contain the secret. git filter-repo --invert-paths --path .env rewrites every commit that touched the file; it is the tool GitHub's own documentation now recommends over the error-prone git filter-branch. Force-push the rewritten history, and note that every commit hash after the rewrite changes, so open pull requests need rebasing.
Hour one: notify and audit
Tell your team to re-clone from the rewritten history, expire old reflog entries with git reflog expire --expire=now --all followed by git gc --prune=now on any surviving copies, and check the provider's usage logs for activity between the leak and the rotation. GitHub's secret scanning, when enabled, reports exposed supported token types to both you and the provider.
When gitignore isn't the right tool
Honest limits, because a generator that pretends .gitignore solves every repo problem is selling pattern-matching as policy:
- Already-tracked files. .gitignore is prophylaxis, not removal. git rm --cached is the cure; see above.
- Secrets already committed. Ignoring .env after pushing it does nothing about the copy in history. Rotate the credential, then clean history with filter-repo if the situation demands it. The ignore rule is for the next file, not the last one.
- Personal noise in a shared repo. Your own scratch files, note drafts, and experimental scripts that nobody else should see belong in .git/info/exclude: same syntax, local-only effect, no PR noise.
- Machine-wide junk. .DS_Store everywhere? Set core.excludesFile once, globally, and stop re-ignoring it per repository for the rest of your career.
- Files other systems need. Some CI setups expect certain ignored-by-convention files to exist, and some Docker builds expect .env. Coordinate the convention with the tooling before ignoring something your pipeline actually reads.
When a pattern refuses to work: check-ignore, then the negation trap
When a pattern refuses to work, Git ships a tool for exactly this moment, and almost nobody runs it before posting the question. git check-ignore -v tells you which file, which line, and which pattern made the decision, or prints nothing at all, which is its own answer:
$ git check-ignore -v build/temp.js
.gitignore:12:build/ build/temp.jsRead the columns left to right: the file that owns the pattern (.gitignore), the line number (12), the pattern itself (build/), and the path being tested (build/temp.js). The output ends one argument instantly: if the winning pattern came from a different file than you expected (say, .git/info/exclude, a global excludes file, or a parent directory's .gitignore), you have found the collision. No output means nothing matches, and the file is not ignored at all.
The second half of the debugging ritual is the broken negation, and it fails in a way that looks like a Git bug. This file re-includes nothing:
# Broken: the directory is ignored, so Git never looks inside it
logs/
!logs/keep.md
# Working: ignore the contents, not the directory itself
logs/*
!logs/keep.mdThe difference is the slash-star. Git does not descend into an excluded directory, so a negation for a file inside it is never even evaluated. logs/* matches the entries inside the directory rather than the directory, which keeps Git looking, and gives the negation something to win against, because last-match-wins applies to those inner entries. Pair it with git status --ignored to watch the directory turn from ignored to partially tracked before committing the fix.
Recovering a bloated repository, measured step by step
Take the bloated repository from the opening and fix it. The numbers below are realistic for a mid-size Node service where node_modules, a few thousand packages and hundreds of megabytes, was committed for two years before anyone noticed.
| Step | Command | Effect |
|---|---|---|
| Measure the damage | git count-objects -vH | Reports the pack size; here, 900 MB |
| Untrack the junk | git rm -r --cached node_modules | Index drops the directory; disk copy stays |
| Commit the removal | git commit -m "stop tracking node_modules" | Future snapshots are clean, history still heavy |
| Rewrite history | git filter-repo --invert-paths --path node_modules | Every commit touching it is rewritten away |
| Force-push | git push --force | The remote loses the blobs; clones must re-clone |
| Reclaim local space | git reflog expire --expire=now --all && git gc --prune=now | Drops unreachable objects from the local store |
Three sources of .gitignore files, compared
| Source | Strength | Weakness |
|---|---|---|
| GitHub's github/gitignore repo | Community-maintained, per-language canonical files | One language per file, no merging of stack + OS + editor |
| gitignore.io (Toptal) | Search-based combos, long history | Single search string, terse output, no per-line explanations |
| This generator | Toggle-button merge of stack + OS + editor, section comments, .env-family defaults | You still need to read the output; templates are starting points, not law |
A note on trust: the GitHub template repository is the upstream reference most generators borrow from, including the good parts and the occasional stale entry. Any generated file should be read before committed, not because generators are wrong, but because your project knows things about itself that no checkbox can. A React Native project and a Next.js project both check the Node box, and what they need after that diverges immediately.
Templates ship inside the page
The generator's 12 sections are bundled with the page, and the merge happens in your browser. No stack selections, no project structure hints and no generated files travel anywhere. The tool keeps working once the page has loaded even if your connection drops, which is a practical property when the laptop-and-airplane repository bootstrap is a real scenario.
There is also nothing to log even if we wanted to: a .gitignore contains no secrets and no personal data beyond your stack fingerprint, and the architecture keeps even that local. Cron building, license generation and this tool all run client-side for the same reason: shipping code to a server for assembly that JavaScript can do locally is overhead for you and risk for everyone.
Frequently asked questions
These are the .gitignore questions that surface in code review and CI tickets: tracked-file confusion, the negation trap, case sensitivity between macOS and Linux CI, and where the .env line really goes. If yours is missing, the contact page takes new questions.
What's the difference between .gitignore and .git/info/exclude?
Both use the same pattern syntax, but .gitignore is committed to the repository and shared with everyone who clones it, while .git/info/exclude lives in your local .git directory and applies only to you. Team-wide ignores (build output, dependencies) belong in .gitignore; personal ignores (your editor scratch files, local experiment scripts) belong in .git/info/exclude or your global excludes file.
Why is a file still tracked after I added it to .gitignore?
Because .gitignore only prevents untracked files from being added; it does nothing to files Git is already tracking. Untrack the file with git rm --cached path/to/file (the --cached flag keeps your local copy) and commit that removal. From then on the ignore rule applies. This is the single most common .gitignore confusion.
Should I ignore the whole .vscode folder?
Commonly yes, but some teams commit specific shared settings. The middle path: ignore .vscode/* and re-include the files your team shares (for example, !.vscode/settings.json and !.vscode/extensions.json). That keeps individual preferences local while shared project settings travel with the repo.
Can I re-include a file inside an ignored directory?
Not if you ignored the directory itself. Git doesn't descend into ignored directories, so a negation like !build/keep.txt under a build/ rule never gets evaluated. Ignore the directory's contents with a wildcard instead: build/* followed by !build/keep.txt works, because the directory itself is no longer excluded. Re-including files under an excluded parent is the classic pattern that fails.
Should .env files ever be committed?
No. Environment files holding secrets should be ignored (.env, .env.local, .env.*.local) and committed as a sanitized .env.example instead, with keys but placeholder values. If a real secret ever lands in history, removing the file later is not enough; rotate the secret, because git history keeps every version ever committed.
Where does my global gitignore live?
Wherever core.excludesFile points. Set it once with git config --global core.excludesFile ~/.gitignore_global, then put OS junk like .DS_Store and editor scratch files there so you never commit them from any repository again. Personal and machine-level noise belongs in the global file; project dependencies belong in each repo's .gitignore.
Does the generator upload my project details anywhere?
No. The template library ships inside the page itself, and the merge you build is assembled in your browser. Nothing about your stack, project names, or chosen frameworks is transmitted; there is nothing sensitive in a .gitignore, but there is also no reason for us to see yours.
Can I have multiple .gitignore files in one repository?
Yes. Git reads a .gitignore in every directory, and the patterns in each apply relative to that directory's location. Deeper files take precedence in the last-match-wins order, so a rule in docs/.gitignore can override one at the root. The common uses are monorepos (one file per service with its own build outputs) and vendored directories you want to treat as a single unit. Most projects stay simpler with one root file and anchored paths.
What's the difference between .gitignore and .gitattributes?
They answer different questions. .gitignore decides which paths never enter the repository. .gitattributes decides how Git handles the files that do enter: line-ending normalization for cross-platform text files, which diff driver to use, export-ignore rules for archive tarballs. Ignoring a path makes attributes for it irrelevant; attributes on a tracked path (like marking *.png binary to stop diff noise) are where the two files cooperate.
How do I test my .gitignore before committing it?
Two dry-run checks cover it. Run git add . -n (the -n flag previews without staging) and scan the list for anything that should have been excluded. For one specific path, git check-ignore -v path prints exactly which rule matched it, or nothing if the file is headed for the index. Doing both on a fresh clone catches the ordering mistakes and the untracked-file surprises before they become a teammate's pull request comment.
Why does my .gitignore work on my Mac but not in CI?
Filesystem case sensitivity. macOS and Windows keep core.ignoreCase on by default, so a pattern written Build/ silently matches a directory named build; then a Linux CI runner with a case-sensitive filesystem honors the pattern exactly as written and lets the directory through. The fix is to match the real capitalization of every path in the file, and to run git check-ignore -v on the CI box when in doubt.
How do I see or clean up the files my .gitignore is hiding?
git status --ignored lists ignored files alongside untracked ones, the fastest way to confirm a new pattern catches what you intended. For cleanup, git clean -Xn is the dry run that shows only ignored files, git clean -Xd deletes them, and the lowercase -x variants also sweep untracked files, so read the flag twice before running it. None of these touch tracked files; that is what git rm --cached is for.
Documentation behind the patterns
Pair the generated file with a LICENSE from the license generator and a validated .env.example from the ENV File Validator; those three files are the bootstrap of a repository that respects its future contributors. For the file itself, the pattern grammar is documented authoritatively in Git's own manual, and the template conventions come from the community repository. These are the references to keep open:
Sources and further reading
- Git documentation: gitignore pattern format(git-scm.com)
- Git documentation: git-check-ignore(git-scm.com)
- github/gitignore: the community template collection(github.com)
- gitignore.io: the long-running Toptal generator(toptal.com)
We cite primary sources (standards bodies, government agencies, official documentation) wherever they exist so you can verify every number on this page yourself.