Skip to content

Gitignore Generator

Tick the languages, editors and operating systems your repository touches and download one .gitignore with a labelled section for each.

Runs in your browserFree, no sign-upLast reviewed

Settings

Results update automatically as you type.

.gitignore

# Generated by PlainToolbox — https://plaintoolbox.com/gitignore-generator

# Node
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
.pnpm-store/
dist/
build/
.next/
.nuxt/
.cache/
coverage/
*.tsbuildinfo

# VS Code
.vscode/*
!.vscode/settings.json
!.vscode/extensions.json
*.code-workspace

# macOS
.DS_Store
.AppleDouble
.LSOverride
._*
.Spotlight-V100
.Trashes

# Environment & secrets
.env
.env.local
.env.*.local
*.pem
*.key
secrets.json

Summary

Sections
4
Patterns
29

Quick answers

What should be in a .gitignore file?
Anything that is generated, downloaded, personal or secret: dependency folders such as node_modules/ and venv/, build output such as dist/ and target/, caches and logs, editor folders such as .idea/, operating system files such as .DS_Store and Thumbs.db, and .env files or private keys.
How do I create a .gitignore file?
Make a plain text file named exactly .gitignore, with the leading dot and no extension, in the top folder of the repository. Put one pattern per line, then add and commit the file like any other. The download button here saves it under that name.
Where does the .gitignore file go?
In the root of the repository, beside the .git folder, so its patterns apply to the whole project. Extra .gitignore files can be placed in subfolders; their rules apply to that folder and everything below it.
Why is Git still tracking a file that is in .gitignore?
Ignore rules only affect files Git is not already tracking. For a file that was committed earlier, run git rm --cached followed by the path, then commit. The file stays on your disk but is removed from the repository from that commit onward.
Should node_modules be in .gitignore?
Yes. The folder is rebuilt from package.json and the lock file by npm install, can grow to hundreds of megabytes, and can contain files built for one operating system. Commit package.json and the lock file and ignore node_modules/.
Should .env files be committed to Git?
No. They usually hold API keys, database passwords and tokens, and anything committed stays readable in the history even after the file is deleted. Ignore .env and commit a .env.example that lists the variable names with empty values.

What Gitignore Generator does

This gitignore generator builds a .gitignore from twelve short, fixed sections: Node, Python, Java, Go, Rust, PHP, VS Code, JetBrains, macOS, Windows, Linux and environment files. Each ticked box adds its patterns under a comment heading, so the default selection of Node, VS Code, macOS and env files gives 29 patterns in 4 sections, and ticking everything gives 77 in 12. The sections are deliberately small, covering dependency folders, build output, caches, editor settings, operating system clutter and secrets, so the file stays readable. The full contents of every section are listed below, which lets you see what you are getting before you commit it.

Every pattern in each gitignore template

The Patterns column matches the count the tool reports when only that box is ticked.

CheckboxPatternsLines added
Node / JavaScript13node_modules/, npm-debug.log*, yarn-debug.log*, yarn-error.log*, pnpm-debug.log*, .pnpm-store/, dist/, build/, .next/, .nuxt/, .cache/, coverage/, *.tsbuildinfo
Python14__pycache__/, *.py[cod], *.egg-info/, .eggs/, build/, dist/, .venv/, venv/, env/, .pytest_cache/, .mypy_cache/, .ruff_cache/, .coverage, htmlcov/
Java / Gradle / Maven8*.class, *.jar, *.war, *.ear, target/, build/, .gradle/, hs_err_pid*
Go6*.exe, *.test, *.out, bin/, vendor/, go.work.sum
Rust3target/, **/*.rs.bk, and a Cargo.lock line with a note (see the list of things to adjust)
PHP / Composer3/vendor/, composer.phar, .phpunit.result.cache
VS Code4.vscode/*, !.vscode/settings.json, !.vscode/extensions.json, *.code-workspace
JetBrains IDEs4.idea/, *.iml, *.iws, out/
macOS6.DS_Store, .AppleDouble, .LSOverride, ._*, .Spotlight-V100, .Trashes
Windows5Thumbs.db, ehthumbs.db, Desktop.ini, $RECYCLE.BIN/, *.lnk
Linux5*~, .fuse_hidden*, .directory, .Trash-*, .nfs*
Env files & secrets6.env, .env.local, .env.*.local, *.pem, *.key, secrets.json

Sections are written in this order, each under a comment such as # Node. The file starts with a one-line comment naming the generator, which you can delete.

Gitignore file sizes for common project setups

Boxes ticked, and the Sections and Patterns figures shown in the Summary.

JavaScript or TypeScript app on a Mac (the default)

Node / JavaScript, VS Code, macOS, Env files & secrets

4 sections, 29 patterns

Python project in VS Code

Python, VS Code, macOS, Env files & secrets

4 sections, 30 patterns

Node front end with a Python back end

Node / JavaScript, Python, VS Code, macOS, Env files & secrets

5 sections, 43 patterns

build/ and dist/ appear in both the Node and the Python section. Repeated lines are harmless to Git.

Java service built in IntelliJ on Windows

Java / Gradle / Maven, JetBrains IDEs, Windows

3 sections, 17 patterns

Team on mixed operating systems

Node / JavaScript, VS Code, macOS, Windows, Linux, Env files & secrets

6 sections, 39 patterns

Lines to review after generating

The sections are general starting points. These are the patterns most likely to need a change for your project.

  • Rust, Cargo.lock: the generated line is Cargo.lock followed by two spaces and a note beginning with #. Git only treats # as a comment at the start of a line, so as written this line matches nothing and Cargo.lock is not ignored. For an application, delete the line. For a library where you do want the lock file ignored, delete the note so the line reads Cargo.lock.
  • Java, *.jar: this also matches gradle/wrapper/gradle-wrapper.jar, which Gradle projects are meant to commit. Add !gradle/wrapper/gradle-wrapper.jar on a new line below the Java section.
  • Go, vendor/ and bin/: remove vendor/ if the project commits its vendored dependencies.
  • Node and Python, build/ and dist/: these match a folder with that name at any depth. If you keep source in a folder called build, anchor or remove the rule.
  • Env files: .env, .env.local and names such as .env.production.local are ignored, but .env.production and .env.development are not. Add .env.* followed by !.env.example if those files hold secrets too.
  • Env files, *.key and *.pem: any file with these extensions is ignored anywhere in the tree, including public test fixtures. Re-include specific files with a ! rule if needed.
  • VS Code: everything in .vscode is ignored except settings.json and extensions.json. Add !.vscode/launch.json or !.vscode/tasks.json if the team shares those.
  • Duplicates across sections, such as target/ in both Java and Rust, are not merged. They do no harm.

Gitignore pattern syntax

PatternWhat it matches
buildAny file or folder named build, at any depth
build/Folders named build only, at any depth, with everything inside
/buildOnly the build file or folder next to this .gitignore
*.logEvery file ending in .log, in any folder
*.py[cod]Files ending in .pyc, .pyo or .pyd
**/*.rs.bkFiles ending in .rs.bk in any folder; ** matches any number of folder levels
docs/*.pdfPDF files directly inside docs, not in its subfolders
!keep.logRe-includes keep.log after an earlier rule ignored it
# textA comment, when # is the first character of the line
\#notesA file literally named #notes; the backslash escapes the #

A file cannot be re-included with ! if its parent folder is ignored, because Git does not look inside ignored folders. That is why the VS Code section ignores .vscode/* and not .vscode/.

Removing files that were committed before the .gitignore existed

Adding a pattern does not untrack anything. If node_modules or a build folder is already in the repository, run git rm -r --cached node_modules and commit. The --cached flag removes the folder from Git's index and leaves the copy on your disk alone. From then on the ignore rule keeps it out.

This fixes future commits only. Every earlier commit still contains the files, and anyone who clones the repository receives that history. For large folders that is merely wasted space. For a password or key it is a leak: treat the credential as exposed, replace it, and if the history must be cleaned use a rewriting tool such as git filter-repo.

To find out why a particular path is or is not ignored, run git check-ignore -v followed by the path. Git prints the file, line number and pattern responsible, which is quicker than reading the whole file.

Step by step

  1. 1

    Tick each language your repository uses: Node / JavaScript, Python, Java / Gradle / Maven, Go, Rust or PHP / Composer. Several can be ticked at once.

  2. 2

    Tick the editors people on the project use: VS Code, JetBrains IDEs, or both.

  3. 3

    Tick the operating systems contributors work on: macOS, Windows and Linux.

  4. 4

    Leave Env files & secrets ticked unless the repository has no local configuration at all. At least one box must be ticked for a file to be produced.

  5. 5

    Copy the text under .gitignore or download the file, save it in the repository root next to the .git folder, and commit it.

Frequently asked questions

Can I add the generated rules to an existing .gitignore?
Yes. Copy the output and paste it at the end of your current file instead of downloading. Later lines take precedence over earlier ones when two rules conflict, so check that a pasted rule does not undo a ! exception you already had.
My language or framework is not listed. What should I do?
This tool has twelve fixed sections and no search. Generate the editor, operating system and env sections here, then add the language's rules by hand or from the template collection GitHub publishes in its github/gitignore repository, which covers far more languages and frameworks.
Should .vscode or .idea be committed?
It is a team decision. Personal state such as window layout and local history should stay out. Shared settings can be useful, which is why the VS Code section keeps settings.json and extensions.json. The JetBrains section ignores the whole .idea folder.
Should package-lock.json or yarn.lock be ignored?
No. Lock files should be committed for applications so that every install resolves to the same versions. None of the sections here ignore package-lock.json, yarn.lock, pnpm-lock.yaml, poetry.lock or composer.lock.
Do I need the macOS section if I use Windows?
Tick the systems of everyone who commits, not only your own. One contributor on a Mac is enough to add .DS_Store files to a pull request. The three operating system sections add 16 patterns between them.
What is a global gitignore?
A personal ignore file that applies to every repository on your machine, set with git config --global core.excludesfile followed by a path. It is a good place for your own editor and operating system files, so projects do not have to list every contributor's tools.
Does .gitignore affect files other people have already pulled?
It does not delete anything. Once you commit a git rm --cached change, the file is removed from collaborators' working copies when they pull, because Git sees it as a deletion. Warn the team first if the file holds local settings they need.
How do I ignore everything in a folder but keep the folder?
Git does not track empty folders. Put a .gitignore inside the folder containing two lines, * and !.gitignore. Everything in the folder is ignored except that file, so the folder itself stays in the repository.

Further reading

Looking for something else? Browse all developer tools or see every tool.