.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

Node projects generate a node_modules/ directory containing all dependencies. This directory is typically the largest in the project and should always be ignored since npm install recreates it from package.json.

Python

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

Java

Java projects produce compiled .class files, JAR archives, and build output directories (target/ for Maven, build/ for Gradle).

Go

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

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"

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.

Is my data safe?

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