Skip to main content

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 (recommended):

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

--logging TYPE

Logging format: console or json

--debug

Enable debug logging

--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:

  1. Fetch versions: Downloads both old (current) and new (latest) template versions

  2. 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

  3. Conflict resolution: Falls back gracefully when automatic merging fails

  4. 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:

black .
isort .
ruff check .

Building documentation:

cd docs
make html

License

MIT License. See LICENSE file for details.

Contributing

Contributions are welcome! Please:

  1. Fork the repository

  2. Create a feature branch

  3. Add tests for new functionality

  4. Run the test suite and linting

  5. Submit a pull request

For bug reports and feature requests, please use the GitHub issue tracker.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ign-0.1.0.tar.gz (77.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ign-0.1.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file ign-0.1.0.tar.gz.

File metadata

  • Download URL: ign-0.1.0.tar.gz
  • Upload date:
  • Size: 77.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.4

File hashes

Hashes for ign-0.1.0.tar.gz
Algorithm Hash digest
SHA256 296a70fa11491a2b80138861c7f219a67b8004e34882d9fe87f0adde47a57587
MD5 cde514122d9358d579964a3bd4cadcce
BLAKE2b-256 16ac1dfae3b42f27e72e0e15bbdcf6953446281517d287ff03d3ebca91c1a0de

See more details on using hashes here.

File details

Details for the file ign-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ign-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.4

File hashes

Hashes for ign-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9f9cf3d34acfa107f61dacfe52982cb4fae848ebfde84b5dbba018eded8efb1
MD5 969d86881d3f3877f810397631e22664
BLAKE2b-256 39d71ea3ff6b37c52d149249a5d586e04035c71386fe7c0e4817fc0d64424b6a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page