| Crates.io | git-ignore-tool |
| lib.rs | git-ignore-tool |
| version | 1.0.1 |
| created_at | 2025-09-29 07:30:01.247717+00 |
| updated_at | 2025-09-29 08:21:01.399777+00 |
| description | A command-line tool to add patterns to git ignore files |
| homepage | https://github.com/andrewleech/git-ignore |
| repository | https://github.com/andrewleech/git-ignore |
| max_upload_size | |
| id | 1859069 |
| size | 78,133 |
A command-line tool for easily adding patterns to git ignore files. Supports adding patterns to .gitignore, .git/info/exclude, or global gitignore files with validation and duplicate detection.
.gitignore, .git/info/exclude, or global gitignoreWith cargo (fastest and most reliable):
cargo install git-ignore-tool
Download pre-built binaries for your platform from the releases page.
Prerequisites: Rust 1.70+ (install via rustup)
git clone https://github.com/andrewleech/git-ignore.git
cd git-ignore
cargo build --release
The binary will be available at target/release/git-ignore.
git clone https://github.com/andrewleech/git-ignore.git
cd git-ignore
cargo build
cargo test
Add patterns to the repository's .gitignore file:
git-ignore "*.pyc" "__pycache__/" "build/"
Add patterns to .git/info/exclude (not shared with others):
git-ignore --local "*.tmp" "my-personal-notes.txt"
Add patterns to your global gitignore:
git-ignore --global "*.log" ".DS_Store"
--local, -l: Add patterns to .git/info/exclude instead of .gitignore--global, -g: Add patterns to global gitignore file--no-validate: Skip pattern validation--allow-duplicates: Allow duplicate patterns to be added--version, -v: Show version information--help, -h: Show help message# Add Python-specific patterns
git-ignore "*.pyc" "*.pyo" "__pycache__/" ".pytest_cache/"
# Add build artifacts (local only, not shared)
git-ignore --local "build/" "dist/" "*.egg-info/"
# Add OS-specific patterns globally
git-ignore --global ".DS_Store" "Thumbs.db" "*.swp"
# Allow duplicates (useful for scripting)
git-ignore --allow-duplicates "*.log"
# Skip validation for special patterns
git-ignore --no-validate "*"
git-ignore automatically validates patterns and provides feedback:
*)./file → file)$ git-ignore "*"
WARNING: Potentially problematic patterns:
*: Pattern is very broad and may ignore more than intended
Added 1 pattern to repository gitignore (.gitignore):
*
Use --no-validate to skip validation when needed.
git-ignore uses semantic exit codes:
0: Success1: Pattern validation failed2: Git repository issues (not in git repo, etc.)3: Configuration issues (no global gitignore configured, etc.)4: File system issues (permission denied, disk full, etc.)130: Interrupted by user (Ctrl+C)255: Unexpected errorTo use --global, configure your global gitignore file:
# Set global gitignore file
git config --global core.excludesfile ~/.gitignore_global
# Or use the default location
mkdir -p ~/.config/git
touch ~/.config/git/ignore
git-ignore is designed to work well in scripts:
#!/bin/bash
# Add standard Python patterns
if git-ignore "*.pyc" "__pycache__/" ".pytest_cache/"; then
echo "Added Python ignore patterns"
else
echo "Failed to add patterns (exit code: $?)" >&2
exit 1
fi
git clone https://github.com/andrewleech/git-ignore.git
cd git-ignore
cargo build
# Unit tests
cargo test --lib
# Integration tests
cargo test --test integration_tests
# All tests
cargo test
# Linting
cargo clippy -- -D warnings
# Formatting
cargo fmt --check
# Full check
cargo clippy --all-targets --all-features -- -D warnings
# Build release binary
cargo build --release
# Test the built binary
./target/release/git-ignore --version
The project consists of three main modules:
git.rs: Git repository detection and path resolutionignore.rs: Core ignore file operations (reading, writing, validation)main.rs: CLI interface and argument parsingSee CLAUDE.md for detailed development information.
git rev-parse support| Feature | git-ignore | Manual editing | Other tools |
|---|---|---|---|
| Duplicate detection | ✅ | ❌ | Varies |
| Pattern validation | ✅ | ❌ | Limited |
| Multiple targets | ✅ | Manual | Limited |
| Git integration | ✅ | ❌ | Basic |
| Cross-platform | ✅ | ✅ | Varies |
| Batch operations | ✅ | Tedious | Limited |
"Not in a git repository"
--local option, the repository must have a .git directory"No global gitignore file configured"
git config --global core.excludesfile ~/.gitignore_global~/.config/git/ignorePermission errors
Patterns not working as expected
--help outputContributions welcome! Please:
See CLAUDE.md for development guidelines.
MIT License. See LICENSE file for details.