Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages

Free tool · Developer tools

.gitignore generator

Tick the templates that match your project and the .gitignore generator writes one file for all of them. The default choice of Node.js, macOS, VS Code, Environment files gives 18 patterns in 25 lines, ready to copy or download.

  • Free
  • No sign-up
  • Runs in your browser

By Maaz Zindani · Updated

Languages and tools
Operating systems
Editors
Other files
Options
Your .gitignore

18 patternsfrom 4 templates

# Node.js node_modules/ npm-debug.log* yarn-debug.log* yarn-error.log* .npm/ .eslintcache *.tsbuildinfo coverage/ # macOS .DS_Store .AppleDouble .LSOverride ._* # VS Code .vscode/* !.vscode/settings.json !.vscode/extensions.json # Environment files .env .env.* !.env.example

Some browsers rename a download that starts with a dot, for example to gitignore.txt. Rename it to .gitignore if that happens.

  • 25 lines in the file
  • No repeated patterns
Templates
Node.js, macOS, VS Code, Environment files
Folder rules
3
Exceptions with !
3
File size
278 bytes

How to use the .gitignore Generator

  1. Tick the templates for your languages, operating systems, editors and other files.
  2. Type any own patterns, one per line. They are written after the templates.
  3. Check the patterns in the result, which show repeated rules written only once.
  4. Press Copy or Download .gitignore and put the file in the root of your repository.

How do I generate a .gitignore file for my project?

A .gitignore file is a plain text list of patterns that tell Git which files to leave alone. Pick one template for each kind of file your project makes. Dependencies, build output, editor folders, system files and local settings are the usual ones. The generator writes the templates in the order shown on the page, adds a comment line above each one if you want it, and writes a pattern only once even when two templates share it.

With Node.js, macOS, VS Code, Environment files ticked, the file has 18 patterns and 4 comment lines. 3 of the rules end in a slash, which marks a folder, and the VS Code and environment templates add 3 exceptions that start with an exclamation mark. For example, the environment template ignores .env and every .env.something file but keeps .env.example, so a sample file with no secrets can still be committed.

Two templates often repeat a rule. Java and Rust both ignore target/, so ticking both gives 5 patterns instead of 6, and the generator reports 1 repeated pattern written once.

What each template ignores
TemplatePatternsFirst patterns
Node.js8node_modules/ npm-debug.log* yarn-debug.log*
Python8__pycache__/ *.py[cod] .venv/
Java4*.class target/ .gradle/
Go4*.exe *.test *.out
Rust2target/ **/*.rs.bk
PHP2vendor/ .phpunit.result.cache
Ruby3*.gem .bundle/ tmp/
.NET4bin/ obj/ *.user
Build output6dist/ build/ out/
Terraform3.terraform/ *.tfstate *.tfstate.*
macOS4.DS_Store .AppleDouble .LSOverride
Windows4Thumbs.db ehthumbs.db Desktop.ini
Linux3*~ .directory .Trash-*
VS Code3.vscode/* !.vscode/settings.json !.vscode/extensions.json
JetBrains IDEs2.idea/ *.iml
Vim and swap files2*.swp *.swo
Environment files3.env .env.* !.env.example
Logs2*.log logs/
Keys and certificates3*.pem *.key *.p12

How do .gitignore patterns work?

Each line is one pattern. A blank line matches nothing, and a line that starts with # is a comment. A slash at the end limits the pattern to folders, so node_modules/ matches the folder but not a file with that name. A slash at the start or in the middle ties the pattern to the folder that holds the .gitignore file, while a pattern without one, such as .DS_Store, matches at any depth.

An asterisk matches any run of characters except a slash, a question mark matches one character, and square brackets match one character from a set or range. A double asterisk between slashes spans any number of folders, so a/**/b matches a/b, a/x/b and a/x/y/b. A leading exclamation mark turns a pattern into an exception that brings back files an earlier pattern removed. Git cannot bring a file back when a folder above it is ignored, which is why the VS Code template ignores .vscode/* and not .vscode/.

Your own patterns can use all of this. With the Node.js template and the two lines /docs/*.html and !/docs/keep.html, the file ends with those lines under a "Your own patterns" comment, 10 patterns in total. Every HTML file directly in docs is ignored except keep.html.

Why is a file still tracked after I add it to .gitignore?

Ignore rules do not affect files that Git already tracks. If a file was committed before the rule existed, the rule changes nothing for it. To stop tracking the file and keep it on disk, run git rm --cached followed by the file name, then commit. After that the rule applies. Removing a secret from the current files does not remove it from older commits, so change any key or password that was committed.

Where you put a rule decides who shares it. Patterns in .gitignore travel with the repository. Patterns in .git/info/exclude apply to your copy only. A file named in core.excludesFile applies to every repository on your machine, which suits editor and system files. When rules conflict, patterns from .gitignore files in deeper folders win over those higher up, and the last matching line within one file wins.

Use it with

Questions

How do I create a .gitignore file?

Pick templates above, press Download .gitignore, and save the file in the top folder of the repository. Then run git status to see that ignored files no longer show up. The default choice gives 18 patterns.

Where does the .gitignore file go?

In the root of the repository, next to the .git folder. A .gitignore file in a subfolder also works and applies to that folder and below.

How do I ignore a file that is already committed?

Run git rm --cached on the file, add its pattern to .gitignore, and commit. The file stays on your disk and Git stops tracking it. Ignore rules alone do not remove tracked files.

What does the exclamation mark do in a pattern?

It makes the pattern an exception. After .env.* ignores every environment file, the line !.env.example brings that one file back so it can be committed.

Why did my download save as gitignore.txt?

Some browsers and systems rename a file whose name starts with a dot. Rename it to .gitignore in your repository folder. Copying the text into a new file works as well.

Does this page send my patterns anywhere?

No. The file is built in your browser from the templates and what you type, and nothing is uploaded.

Sources

The tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations are checked against the tool's own output.