smart-gitignore
v1.2.0
Published
Smart .gitignore generator with automatic stack detection
Maintainers
Readme
smart-gitignore
Smart .gitignore generator based on automatic detection of your project's technology stack.
🎯 Purpose
smart-gitignore automatically analyzes your project directory, detects the technologies used (Java, Node.js, Docker, Ruby, IDEs, etc.) and generates or updates an appropriate .gitignore file using templates from GitHub/gitignore (primary source), with fallback to gitignore.io and local templates.
Why use it?
- ✅ Automatic detection: No need to know which stacks to add manually
- ✅ Smart merge: Preserves existing comments and rules
- ✅ No duplicates: Automatically removes duplicate entries
- ✅ Robust fallback: GitHub → gitignore.io → local templates
- ✅ Updated templates: Uses official GitHub/gitignore templates
- ✅ Extensible: Easy to add new detections
🚀 How to Use
Global Installation (Optional)
npm install -g smart-gitignoreUsage via npx (Recommended)
npx smart-gitignoreOptions
npx smart-gitignore [options]
Options:
-d, --dir <path> Directory to scan (default: current directory)
-f, --force Overwrite existing .gitignore without merging
-v, --verbose Verbose mode
-h, --help Display help
-V, --version Display versionExamples
# Generate .gitignore in current directory
npx smart-gitignore
# Scan specific directory
npx smart-gitignore --dir /path/to/project
# Overwrite existing .gitignore
npx smart-gitignore --force
# Verbose mode for debugging
npx smart-gitignore --verbose🔍 Stack Detection
smart-gitignore automatically detects the following technologies:
Languages & Frameworks
- Java:
pom.xml,build.gradle,.javafiles - Node.js:
package.json,yarn.lock,pnpm-lock.yaml,package-lock.json - Ruby:
Gemfile,Rakefile,.ruby-version - Python:
requirements.txt,Pipfile,pyproject.toml,manage.py - Go:
go.mod,go.sum - Rust:
Cargo.toml,Cargo.lock - PHP:
composer.json,composer.lock - .NET:
.csproj,.sln,project.json
Tools & Environments
- Maven:
pom.xml - Gradle:
build.gradle,settings.gradle - Docker:
Dockerfile,docker-compose.yml - Yarn:
yarn.lock - pnpm:
pnpm-lock.yaml - npm:
package-lock.json
IDEs
- IntelliJ IDEA:
.idea/ - VS Code:
.vscode/ - Eclipse:
.eclipse/,.settings/,.project,.classpath
Others
- dotenv:
.env,.env.local,.env.development,.env.production
📁 Project Structure
smart-gitignore/
├── src/
│ ├── scanner.ts # File detection in directory
│ ├── detector.ts # File → stack mapping
│ ├── generator.ts # API call + fallback
│ ├── merger.ts # Safe .gitignore merge
│ └── index.ts # CLI entrypoint
├── templates/ # Local fallback templates
│ ├── default.gitignore
│ ├── node.gitignore
│ └── java.gitignore
├── dist/ # Compiled code (generated)
├── package.json
├── tsconfig.json
├── README.md
└── LICENSE🔧 Development
Prerequisites
- Node.js >= 18.0.0
- npm or yarn
Setup
# Clone the repository
git clone https://github.com/Otto-Schmitz/smart-gitignore.git
cd smart-gitignore
# Install dependencies
npm install
# Compile TypeScript
npm run build
# Run locally
npm run devAvailable Scripts
npm run build # Compile TypeScript to JavaScript
npm run start # Run compiled version
npm run dev # Run with ts-node (development)🗺️ Roadmap
Version 1.0 (MVP) ✅
- [x] Automatic stack detection
- [x] Integration with gitignore.io API
- [x] Fallback to local templates
- [x] Smart merge of existing .gitignore
- [x] Duplicate removal
- [x] User comment preservation
Version 1.1 (Planned)
- [ ] Support for more languages (Kotlin, Swift, Dart, etc.)
- [ ] API template caching
- [ ] Interactive mode for stack selection
- [ ] Existing .gitignore validation
Version 2.0 (Future)
- [ ] VS Code extension
- [ ] IntelliJ IDEA plugin
- [ ] Git hooks integration
- [ ] REST API for CI/CD usage
- [ ] Support for multiple .gitignore files (subdirectories)
🤝 Contributing
Contributions are welcome! Feel free to:
- Report bugs: Open an issue describing the problem
- Suggest features: Share your ideas in an issue
- Submit PRs:
- Fork the project
- Create a branch for your feature (
git checkout -b feature/new-feature) - Commit your changes (
git commit -m 'Add new feature') - Push to the branch (
git push origin feature/new-feature) - Open a Pull Request
Adding New Detections
To add a new stack detection, edit src/detector.ts:
private readonly detectionMap: Map<string, string[]> = new Map([
// ... existing detections
['your-file.ext', ['your-stack']],
]);Adding Local Templates
Add .gitignore files in the templates/ folder with the stack name:
templates/
└── your-stack.gitignore📝 License
This project is licensed under the MIT License.
🙏 Acknowledgments
- GitHub/gitignore for the official templates
- gitignore.io for the API and templates
- Open-source community for inspiration and feedback
📧 Contact
For questions, suggestions, or issues, open an issue on GitHub.
Made with ❤️ by the open-source community
