Skip to main content

🚀 GitIgnore Generator (gitign)

A powerful and user-friendly Python script to generate .gitignore files with default entries, custom patterns, or templates from gitignore.io and to effortlessly create, manage, and clean your .gitignore files. Features rich console output and smart duplicate detection.

✨ Features

  • 🎯 Smart Generation: Create .gitignore files with sensible defaults
  • 🔄 Template Support: Fetch templates from gitignore.io for popular frameworks
  • 🛡️ Duplicate Prevention: Automatically detects and prevents duplicate entries
  • 🧹 Cleanup Tool: Remove duplicates from existing .gitignore files
  • 📖 Syntax Highlighting: Beautiful syntax-highlighted file reading
  • 🎨 Rich Console Output: Colorful and informative terminal interface
  • ⚡ Auto-Append Mode: Intelligently appends to existing files
  • 💾 Backup Support: Creates backups when cleaning files

📋 Requirements

  • Python 3.6+
  • Rich library (pip install rich)
  • licface (pip install licface) (optional, for enhanced help formatting)

🔧 Installation

  1. Clone or download the script:
git clone https://github.com/cumulus13/gitignore.git
cd gitignore
  1. Install dependencies:
pip install rich
  1. Make the script executable (optional):
chmod +x gitignore.py

🚀 Quick Start

Basic Usage

# Generate .gitignore with default entries
python gitignore.py

# Add custom entries (auto-appends if file exists)
python gitignore.py "*.log" "temp/" "config.local"

# Use templates from gitignore.io
python gitignore.py -t python node react

# Read existing .gitignore with syntax highlighting
python gitignore.py -r

📖 Usage Examples

🎯 Creating New .gitignore Files

# Basic generation with defaults
gitign

# Generate with custom entries
gitign "*.tmp" "debug.log" "*.cache"

# Generate with templates
gitign -t python django

# Generate without default entries
gitign --no-defaults -t python

# Force overwrite existing file
gitign -f "*.backup"

📝 Adding to Existing Files

# Auto-append mode (detects existing file)
gitign "new_pattern" "*.local"

gitign -d "secrets.txt" -d "temp/" -d "*.log"

# Explicit append mode
gitign -a "build/" "dist/"

# Add multiple entries with different separators
gitign "file1,file2;file3|file4"

# Combine Template and Custom Entries
gitign -t node -d ".env" -d "dist_electron/"

🧹 Cleaning Duplicates

# Preview duplicates without changes
gitign --clean --preview

# Remove duplicates (creates backup by default)
gitign --clean

# Remove duplicates without backup
gitign --clean --no-backup

# Clean file in specific directory
gitign --clean -p /path/to/project

📖 Reading Files

# Read .gitignore with syntax highlighting
gitign -r

# Read from specific directory
gitign -r -p /path/to/project

⚙️ Command Line Options

Main Options

Option Short Description
--path -p Target directory path (default: current directory)
--data -d Additional entries (can be repeated)
--template -t Templates from gitignore.io
--append -a Append to existing file without overwrite
--force -f Skip confirmation prompt
--no-defaults Don't include default entries
--read -r Read and display .gitignore content
--version -v Show version information

Cleaning Options

Option Description
--clean Clean duplicate entries
--preview Preview changes without applying
--no-backup Don't create backup file

🎯 All Options

Option Description
-p PATH, --path PATH Target directory for the .gitignore file. (Default: current directory .)
-d DATA, --data DATA Add a custom entry. Can be used multiple times.
-t TEMPLATE [TEMPLATE ...], --template TEMPLATE [TEMPLATE ...] Use one or more templates from gitignore.io (e.g., python, node, java).
-a, --append Add entries to an existing .gitignore file instead of overwriting it.
-f, --force Skip the overwrite confirmation prompt if .gitignore already exists.
--no-defaults Prevent the script from adding its built-in default entries.
-r, --read Display the content of the .gitignore file in the specified path with syntax highlighting.
--clean Remove duplicate entries from the .gitignore file.
--preview (With --clean) Show which duplicates would be removed without changing the file.
--no-backup (With --clean) Do not create a .gitignore.bak backup file.
-h, --help Show a help message and exit.
-v, --version Show the script version and exit.

🧾 Positional Arguments (ENTRIES)

You can pass entries directly as arguments. The script intelligently splits them based on common delimiters:

  • Comma (,): gitign "*.tmp,*.log"
  • Semicolon (;): gitign "build/;dist/"
  • Colon (:): gitign "secrets.txt:config.ini"
  • Pipe (|): gitign "temp|cache"
  • Space ( ): gitign .vscode .idea
  • Newline (\n): Useful when piping input.
  • Brackets: gitign "[*.bak,*.old]" or gitign "{*.tmp,*.temp}"
  • Quotes: gitign "'my file.txt'" or gitign '"another file.log"'

Note: Backslashes (\) in entries are automatically converted to forward slashes (/) for cross-platform compatibility.

🎨 Default Entries

The script includes these default entries by default:

*.pyc
*.bak
*.zip
*.rar
*.7z
*.mp3
*.wav
*.sublime-workspace
.hg/
build/
*.hgignore
*.hgtags
*dist/
*.egg-info/
traceback.log
__pycache__/
*.log

🌟 Advanced Features

📝 Multiple Entry Formats

The script supports various entry formats:

# Comma-separated
python gitignore.py "file1,file2,file3"

# Space-separated (use quotes)
python gitignore.py "file1 file2 file3"

# Semicolon-separated
python gitignore.py "file1;file2;file3"

# Array-like format
python gitignore.py "[file1,file2,file3]"

# Quoted entries
python gitignore.py '"special file.txt"' "'another file.log'"

🔄 Template Examples

Popular templates available from gitignore.io:

# Programming languages
python gitignore.py -t python
python gitignore.py -t node javascript
python gitignore.py -t java maven
python gitignore.py -t csharp dotnetcore

# Frameworks
python gitignore.py -t react vue angular
python gitignore.py -t django flask
python gitignore.py -t rails laravel

# IDEs and editors
python gitignore.py -t vscode visualstudio
python gitignore.py -t intellij pycharm
python gitignore.py -t sublime vim

# Operating systems
python gitignore.py -t windows macos linux

# Combined templates
python gitignore.py -t python django vscode

🛡️ Smart Duplicate Detection

The script automatically:

  • ✅ Reads existing .gitignore entries
  • ✅ Prevents adding duplicate patterns
  • ✅ Preserves comments and formatting
  • ✅ Shows informative messages about skipped duplicates

🔧 Configuration

Environment Variables

  • TRACEBACK=1: Enable detailed error tracebacks

🎯 Use Cases

For New Projects

# Python project
python gitignore.py -t python

# Node.js project
python gitignore.py -t node

# Full-stack project
python gitignore.py -t python node react vscode

For Existing Projects

# Add build artifacts
python gitignore.py "build/" "dist/" "*.map"

# Add IDE files
python gitignore.py ".vscode/" ".idea/" "*.swp"

# Add OS-specific files
python gitignore.py -t macos windows linux

Maintenance Tasks

# Clean up duplicated .gitignore
python gitignore.py --clean

# Preview what would be cleaned
python gitignore.py --clean --preview

# Backup and clean
python gitignore.py --clean  # Creates .gitignore.bak automatically

🐛 Troubleshooting

Common Issues

Unicode characters not displaying properly

  • Ensure your terminal supports UTF-8 encoding
  • On Windows, try using Windows Terminal or enable UTF-8 support

Permission errors

  • Make sure you have write permissions in the target directory
  • Run with appropriate privileges if needed

Template fetch failures

  • Check your internet connection
  • Verify template names are correct (see gitignore.io)

Debug Mode

Enable detailed tracebacks:

export TRACEBACK=1  # Linux/Mac
set TRACEBACK=1     # Windows
python gitignore.py [options]

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Development Setup

git clone https://github.com/cumulus13/gitignore.git
cd gitignore
pip install rich

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • gitignore.io for providing the template API
  • Rich for beautiful terminal output
  • The Python community for inspiration and support

📞 Support


Author

Made with ❤️ by Hadi Cahyadi

⭐ Star this repo if you find it helpful! ⭐

License

MIT License. See LICENSE.

Coffee

Buy Me a Coffee

Donate via Ko-fi

Support me on Patreon

Medium

Metadata

Release files for gitign 0.18.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gitign 0.18.2
File Size Uploaded
gitign-0.18.2.tar.gz 12.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gitign 0.18.2
File Interpreter ABI Platform
gitign-0.18.2-py3-none-any.whl Python 3 none any Details

Total release size: 23.8 kB

Release files / gitign-0.18.2.tar.gz

Download URL gitign-0.18.2.tar.gz
Size 12.3 kB
Tags Source
SHA-256 checksum
How to use checksums
df915e89cb393adf90a29d284ad933e36dfb87ac9f47efb241289bd1b837a7dd
BLAKE2b-256 checksum
How to use checksums
381656d89689ef6d4d99d42dd0bb7cf0efb7f76e5a612d7429b30fe22b4c1ab1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / gitign-0.18.2-py3-none-any.whl

Download URL gitign-0.18.2-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa3f37ea7e4f74c4fbc980e172e3f98888deda286231f6c50aa1d3ef5b8bcdc6
BLAKE2b-256 checksum
How to use checksums
21fcd02588ae0e890dc565e7cc74be61fc2968e515527e1db324de218d33ee50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.18.2 This release

2 release files

0.18

2 release files

0.17

2 release files

0.16

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page