.gitignore Generator
Generate .gitignore files for various project types and platforms.
Understanding .gitignore
The .gitignore file tells Git which files and directories to ignore in a project. This prevents sensitive information, build artifacts, and temporary files from being committed to your repository.
Why Use .gitignore?
Security
- Keep credentials and API keys out of version control
- Prevent .env files from being committed
- Protect sensitive configuration files
Performance
- Reduce repository size
- Speed up Git operations
- Avoid tracking large binary files
Cleanliness
- Keep repository organized
- Avoid tracking build artifacts
- Ignore OS-specific files
Collaboration
- Prevent merge conflicts on IDE files
- Allow team members to use different editors
- Keep everyone's local configs private
.gitignore Pattern Syntax
| Pattern | Description | Example |
|---|---|---|
file.txt |
Ignore specific file | Ignores file.txt in any directory |
*.log |
Wildcard: any characters | Ignores all .log files |
temp/ |
Ignore directory | Ignores entire temp directory |
/build |
Ignore in root only | Ignores /build but not src/build |
**/logs |
Match in any directory | Ignores logs folder anywhere |
docs/**/*.pdf |
Recursive pattern | Ignores all PDFs in docs subdirs |
!important.log |
Negate (don't ignore) | Track this file even if *.log ignored |
# comment |
Comment line | Add explanatory comments |
Common Files to Ignore
node_modules/- Node.js packagesvendor/- PHP/Ruby dependencies__pycache__/- Python bytecodevenv/- Python virtual environmentpackages/- .NET packages
dist/,build/- Build output*.o,*.a- Compiled object files*.class- Java compiled classes*.pyc- Python compiled filestarget/- Maven/Gradle output
.env,.env.local- Environment variablessecrets.json- API keys and secretsconfig/local.yml- Local configuration*.pem,*.key- Private keyscredentials.json- Credentials
.DS_Store- macOS folder attributesThumbs.db- Windows thumbnail cachedesktop.ini- Windows folder config*~- Backup files
.vscode/- VS Code settings.idea/- IntelliJ/WebStorm*.swp,*.swo- Vim swap files.project,.classpath- Eclipse
Best Practices
DO:
- Create .gitignore before first commit
- Use comments to organize sections
- Be specific to avoid over-ignoring
- Commit .gitignore to repository
- Use templates for common project types
DON'T:
- Ignore .gitignore itself
- Commit and then add to .gitignore (remove first)
- Use overly broad patterns
- Forget to ignore IDE-specific files
Removing Already-Committed Files
If you already committed files that should be ignored:
# Remove from Git but keep locally
git rm --cached filename
# Remove entire directory
git rm -r --cached directory/
# Commit the removal
git commit -m "Remove ignored files from Git"
Never Commit!
Always ignore:
- Passwords & API keys
- Private keys (.pem, .key)
- .env files
- Database files
- User uploaded content
- Compiled binaries
- Large files (>100MB)