.gitignore Generator

Build a .gitignore file by selecting languages and frameworks

What is .gitignore?

A .gitignore file is a plain text file in a Git repository that specifies which files and directories Git should ignore. When you run git add or git status, Git checks the .gitignore rules and excludes matching files from being tracked.

Every project generates files that shouldn’t be committed to version control — build artifacts, dependency directories, IDE configuration files, compiled binaries, log files, and environment variables containing secrets. The .gitignore file keeps your repository clean and focused on source code.

How .gitignore Patterns Work

Each line in a .gitignore file specifies a pattern. Git uses glob-style matching:

  • * matches any number of characters (except /)
  • ? matches a single character
  • ** matches directories recursively
  • ! negates a pattern (un-ignores a previously ignored path)
  • Lines starting with # are comments
  • Trailing / matches directories only
# Ignore all .log files
*.log

# But keep error.log
!error.log

# Ignore the build directory
build/

# Ignore all .env files in any directory
**/.env

How to Use This Tool

  1. Select your languages and frameworks by checking the relevant boxes
  2. Select your operating system for OS-specific ignores
  3. Select your IDE to exclude editor configuration files
  4. Click “Generate” to build your .gitignore
  5. Copy the result and save it as .gitignore in your project root

Common .gitignore Templates

Node.js / JavaScript

Node projects generate a node_modules/ directory containing all dependencies — often hundreds of megabytes. Always ignore it since npm install or yarn install recreates it from package.json. Also ignore .next/ for Next.js, .nuxt/ for Nuxt, dist/ for bundled output, and .env files containing API keys.

node_modules/
dist/
.next/
.nuxt/
.env
.env.local
*.tsbuildinfo

Python

Python creates __pycache__/ directories, .pyc bytecode files, virtual environments (venv/, .env/), and distribution artifacts (dist/, *.egg-info/). If you use Jupyter, ignore .ipynb_checkpoints/.

__pycache__/
*.py[cod]
venv/
.env
dist/
*.egg-info/
.ipynb_checkpoints/

Java

Java projects produce compiled .class files, JAR archives, and build output directories (target/ for Maven, build/ for Gradle). IDE-specific directories like .idea/ (IntelliJ) or .settings/ (Eclipse) should also be ignored.

Go

Go modules cache dependencies and produce binary outputs. The vendor/ directory may or may not be committed depending on team preference.

Rust

Rust stores compiled artifacts in the target/ directory, which can grow very large. The Cargo.lock file is typically committed for binaries but ignored for libraries.

target/
*.pdb

C# / .NET

.NET projects produce bin/ and obj/ directories, NuGet packages in packages/, and user-specific project settings (.suo, .user files).

bin/
obj/
packages/
*.suo
*.user

Best Practices

  • Start with a template: Use this tool to get a solid baseline, then customize
  • Be specific: Avoid overly broad patterns like * that might catch important files
  • Document unusual rules: Add comments explaining non-obvious ignore patterns
  • Use a global gitignore: Put OS and IDE patterns in ~/.gitignore_global instead of every project
  • Review regularly: As your project evolves, update the .gitignore to match
  • Never ignore the .gitignore: The .gitignore file itself should be committed

.gitignore vs .git/info/exclude

While .gitignore is committed and shared with all collaborators, .git/info/exclude works the same way but is local to your machine. Use exclude for personal patterns you don’t want to share (e.g., your specific editor’s files).

Fixing Already-Tracked Files

If you add a rule to .gitignore but the file is already tracked, Git continues tracking it. To fix this:

# Remove file from tracking (keeps the local file)
git rm --cached filename

# Remove entire directory from tracking
git rm -r --cached directory/

# Rebuild the index from scratch
git rm -r --cached .
git add .
git commit -m "Apply .gitignore rules"

Debugging .gitignore Issues

When your .gitignore rules seem to have no effect, work through these checks:

  1. Already tracked? The most common cause. Run git ls-files <path> — if the file appears, it’s tracked and you need git rm --cached first.
  2. Wrong directory? A .gitignore in frontend/ won’t affect files in backend/. Place the rule in the correct .gitignore or in the root one.
  3. Pattern syntax error? A leading slash (/build) anchors the pattern to that .gitignore’s directory. Without the slash, build matches at any depth.
  4. Negation override? A later ! rule can re-include files you thought were ignored. Run git check-ignore -v <file> to see which rule is matching (or not matching) a specific path.
  5. Whitespace? Trailing spaces in a pattern can cause silent mismatches. Check with cat -A .gitignore.
# Show which .gitignore rule applies to a file
git check-ignore -v path/to/file

# List all ignored files
git status --ignored

Setting Up a Global Gitignore

OS-specific files (.DS_Store, Thumbs.db) and editor directories (.idea/, .vscode/, *.swp) clutter every repository if you add them per-project. A global .gitignore solves this once:

# Tell Git where your global ignore file lives
git config --global core.excludesfile ~/.gitignore_global

Then add your patterns to ~/.gitignore_global:

# macOS
.DS_Store
._*

# Windows
Thumbs.db
Desktop.ini

# Editors
.idea/
.vscode/
*.swp
*~

This keeps project .gitignore files focused on project-specific rules while your personal environment noise is handled globally.

.gitignore Generator vs GitHub Templates

GitHub offers a collection of .gitignore templates at github/gitignore. These are single-language templates — one file per language. Our generator lets you combine multiple languages, frameworks, IDEs, and operating systems into a single file, which is closer to what real projects need. A typical web project, for example, needs Node.js rules, IDE ignores, and OS file patterns all in one .gitignore.

Frequently Asked Questions

What is a .gitignore file?

A .gitignore file tells Git which files and directories to ignore when tracking changes. It prevents build artifacts, dependencies, IDE settings, and sensitive files from being committed to your repository.

Where should I place my .gitignore file?

Place the .gitignore file in the root directory of your Git repository. You can also have additional .gitignore files in subdirectories to apply rules only within those directories.

Can I have multiple .gitignore files?

Yes. Git supports .gitignore files in any directory. Rules in a subdirectory's .gitignore only apply to files within that directory and its children. A global .gitignore in your home directory applies to all repositories.

Why are already-tracked files not being ignored?

Adding a path to .gitignore only affects untracked files. If a file is already tracked by Git, you need to remove it from the index first with 'git rm --cached <file>' before the ignore rule takes effect.

Why is my .gitignore not working?

The most common cause is that the files were already tracked before the rule was added. Run 'git rm -r --cached .' followed by 'git add .' to re-apply all ignore rules. Other causes include incorrect pattern syntax, the rule being in the wrong .gitignore file, or a negation pattern (!) later in the file overriding your rule.

How do I create a global .gitignore?

Run 'git config --global core.excludesfile ~/.gitignore_global', then create that file and add patterns for OS files (like .DS_Store or Thumbs.db) and IDE settings (like .idea/ or .vscode/) that you never want committed in any repository.

Is my data safe?

Yes. The .gitignore file is generated entirely in your browser. Nothing is sent to any server.