Beyond .gitignore: Advanced Git ignore strategies
While .gitignore is the most common way to exclude files from Git tracking, it's not your only option. Sometimes you need more targeted approaches that don't affect the entire team or require different levels of persistence.
1. Repository-specific excludes: .git/info/exclude
When you need to ignore files without affecting other developers or modifying the shared .gitignore, use the local exclude file:
# Edit the local exclude file
echo "my-local-config.json" >> .git/info/exclude
echo "*.local" >> .git/info/exclude
When to use:
- Personal IDE settings files that vary between developers
- Local testing scripts that shouldn't be shared
- Temporary files specific to your workflow
- Files that would clutter the shared
.gitignore
Key benefits:
- Never gets committed or shared with the team
- Survives across branch switches
- Perfect for developer-specific patterns
2. System-wide global ignores
Set up patterns that apply to all your Git repositories system-wide:
# Configure global gitignore file
git config --global core.excludesfile ~/.gitignore_global
# Create and populate the global ignore file
echo ".DS_Store" >> ~/.gitignore_global
echo "Thumbs.db" >> ~/.gitignore_global
echo "*.swp" >> ~/.gitignore_global
echo "*.swo" >> ~/.gitignore_global
Common global ignore patterns:
# macOS
.DS_Store
.AppleDouble
.LSOverride
# Windows
Thumbs.db
ehthumbs.db
Desktop.ini
# Editor backups
*~
*.swp
*.swo
# IDE files
.vscode/
.idea/
*.sublime-*
When to use:
- Operating system generated files
- Editor/IDE backup files
- Personal tools that create files in any project
- Patterns that apply to all your work
3. Temporary ignoring with skip-worktree
Temporarily ignore changes to tracked files without removing them:
# Ignore changes to a tracked file temporarily
git update-index --skip-worktree config/database.yml
# See which files are being skipped
git ls-files -v | grep "^S"
# Stop ignoring (make Git track changes again)
git update-index --no-skip-worktree config/database.yml
When to use:
- Configuration files you need to modify locally but not commit
- Files that need different values for development vs production
- Temporary modifications that shouldn't be tracked
4. Assume unchanged for performance
Tell Git to assume a tracked file hasn't changed (use carefully):
# Mark file as unchanged (Git won't check it)
git update-index --assume-unchanged large-binary-file.bin
# List assumed unchanged files
git ls-files -v | grep "^h"
# Start tracking changes again
git update-index --no-assume-unchanged large-binary-file.bin
When to use:
- Large files that rarely change (performance optimization)
- Files you know haven't changed but Git keeps detecting as modified
⚠️ Warning: Use sparingly - Git won't detect actual changes to these files.
5. Sparse checkout for partial repositories
Ignore entire sections of a repository:
# Enable sparse checkout
git config core.sparseCheckout true
# Define which folders to include
echo "src/" > .git/info/sparse-checkout
echo "docs/" >> .git/info/sparse-checkout
# Apply the sparse checkout
git read-tree -m -u HEAD
When to use:
- Large monorepos where you only work on specific parts
- Excluding heavy assets or documentation you don't need locally
Choosing the right approach
.gitignore - Repository-wide, shared with team, persistent
→ Standard ignore patterns for the team
.git/info/exclude - Repository-wide, local only, persistent
→ Personal ignores, local-only files
Global exclude - All repositories, local only, persistent
→ OS/editor files, personal tooling
skip-worktree - Per file, local only, temporary
→ Temporary local modifications to tracked files
assume-unchanged - Per file, local only, temporary
→ Performance optimization for large unchanged files
Sparse checkout - Repository-wide, local only, persistent
→ Working with partial repository content
Pro tips
Debugging ignore issues:
# Check why a file is being ignored
git check-ignore -v path/to/file
# See all ignore rules affecting a path
git status --ignored path/to/directory
Clean up after experiments:
# Reset all skip-worktree flags
git ls-files -v | grep "^S" | cut -c3- | xargs -r git update-index --no-skip-worktree
# Reset all assume-unchanged flags
git ls-files -v | grep "^h" | cut -c3- | xargs -r git update-index --no-assume-unchanged
The key is matching your ignore strategy to your specific needs - from team-wide standards to personal workflow optimizations.