A tool for composing and synchronizing .gitignore from GitHub's template collection.
Project description
A tool for composing and synchronizing .gitignore from GitHub’s template collection.
Description
ign automatically manages .gitignore files by synchronizing them with templates from GitHub’s gitignore repository. It intelligently merges your local modifications with upstream template changes, preserving your customizations while keeping templates up to date.
Key Features
Template synchronization: Automatically update .gitignore templates from GitHub
Local modification preservation: Keeps your custom additions while updating templates
Intelligent merging: Uses diff/patch algorithms to resolve conflicts
Multiple merge strategies: Tries different approaches to apply changes safely
Auto-detection: Automatically detects existing templates in your .gitignore
Flexible input/output: Works with files or stdin/stdout
Dry-run mode: Preview changes before applying them
Installation
Using uv:
uv add ign
Using pip:
pip install ign
Usage
Basic Usage
Add templates to your .gitignore:
ign Python Node
Update existing templates:
ign
Sync specific templates with version pinning:
ign Python@main Node@abc1234
Command Line Options
ign [OPTIONS] [TEMPLATE[@HASH]...]
Options:
- -f, --file FILE
Input .gitignore file (default: .gitignore, - for stdin)
- -o, --output FILE
Output file (default: same as input, - for stdout)
- -d, --diff
Show unified diff of changes
- -n, --dry-run
Preview changes without writing
- -v, --verbose
Verbose output: enable debug logging
- -q, --quiet
Quiet output: only show errors and warnings
- --logging TYPE
Logging format: console or json (default: console if TTY, otherwise JSON)
- --debug
All-debug output: enable debug logging on all libraries
- --version
Show version and exit
Arguments:
- TEMPLATE[@HASH] GitHub template names (without .gitignore extension)
Optional @HASH pins to specific commit
Examples
Add Python and Node.js templates:
ign Python Node
Update all existing templates:
ign
Preview changes without applying:
ign --dry-run --diff
Use with custom file:
ign --file my-project/.gitignore Java Maven
Read from stdin, write to stdout:
cat .gitignore | ign -f- Python > new-gitignore
Pin template to specific version:
ign Python@4f15b43 Node@latest
How It Works
Template Markers
ign uses special marker comments to track template sections:
# --- BEGIN https://raw.githubusercontent.com/github/gitignore/{SHA}/{TEMPLATE}.gitignore ---
# Template content here
# --- END https://raw.githubusercontent.com/github/gitignore/{SHA}/{TEMPLATE}.gitignore ---
These markers allow ign to:
Identify which templates are already included
Track the version (SHA) of each template
Preserve local modifications between updates
Merge Strategy
When updating templates, ign uses a sophisticated merge algorithm:
Fetch versions: Downloads both old (current) and new (latest) template versions
Apply strategies: Tries two different merge approaches:
Strategy A: Apply (new - old) changes to your local modifications
Strategy B: Apply (local - old) changes to the new template
Conflict resolution: Falls back gracefully when automatic merging fails
Preserve customizations: Your local additions are always preserved
Local Modifications
You can safely add custom rules within template sections. For example:
# --- BEGIN https://raw.githubusercontent.com/github/gitignore/.../Python.gitignore --- # Original Python template content... # Your custom additions *.local /my-project-specific-file # --- END https://raw.githubusercontent.com/github/gitignore/.../Python.gitignore ---
These modifications will be preserved during template updates.
Configuration
Environment Variables
- GITHUB_API_TOKEN
Optional GitHub API token for higher rate limits. Useful for heavy usage or when working with private repositories.
Example .env file:
GITHUB_API_TOKEN=ghp_your_token_here
Template Sources
Templates are fetched from the official GitHub gitignore repository. Available templates include:
Languages: Python, Java, JavaScript, Go, Rust, C++, etc.
Frameworks: Node, Django, Rails, Laravel, etc.
Tools: JetBrains, VisualStudio, Vim, macOS, Windows, etc.
Platforms: Android, iOS, Unity, etc.
For a complete list, visit: https://github.com/github/gitignore
Troubleshooting
Common Issues
- Template not found
Ensure the template name matches exactly (case-sensitive) with files in the GitHub repository. Check https://github.com/github/gitignore for available templates.
- Merge conflicts
If automatic merging fails, ign will preserve your current content and log the issue. You may need to manually resolve conflicts.
- API rate limits
Set GITHUB_API_TOKEN environment variable to increase rate limits.
- Missing END marker
If you manually edit marker comments, ensure BEGIN/END pairs match exactly. Use --debug for detailed error information.
Debug Mode
Enable debug logging for detailed information:
ign --debug --verbose Python
This shows:
Template fetching details
Merge strategy decisions
Diff application results
API request information
Development
Setting up development environment:
git clone https://github.com/astralblue/ign.git cd ign uv sync
Running tests:
pytest
Code formatting:
ruff check --fix && ruff format
Building documentation:
cd docs make html
License
MIT License. See LICENSE file for details.
Contributing
Contributions are welcome! Please:
Fork the repository
Create a feature branch
Add tests for new functionality
Run the test suite and linting
Submit a pull request
For bug reports and feature requests, please use the GitHub issue tracker.
Links
Repository: https://github.com/astralblue/ign
GitHub Templates: https://github.com/github/gitignore
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ign-0.1.1.tar.gz.
File metadata
- Download URL: ign-0.1.1.tar.gz
- Upload date:
- Size: 75.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
adfd8c3312b7ae1c5f7ae5a50ea7bfbb846675b0faab6b31e5021d3ae9ac0b75
|
|
| MD5 |
6526f67c91f81c1d4a721e7c6b0ff212
|
|
| BLAKE2b-256 |
444db94a1c29ad5a4085dc0284eafe4ccbba81c3da98307f5a3bcf345107b855
|
File details
Details for the file ign-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ign-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56933e26a44b9ba9d13e92ce7a65766e922c017fa0f284b633a08b6142987a0b
|
|
| MD5 |
99c5f5027997b3e11c8a87a254e65f52
|
|
| BLAKE2b-256 |
a32ebd267aa020d693b3e7845bcefec6dbb58ddcc97d46b34eca3b502eb5dd86
|