Skip to content
SysTutorials
  • SysTutorialsExpand
    • Linux & Systems Administration Academy
    • Web3 & Crypto Academy
    • Programming Academy
    • Systems & Architecture Academy
  • Subscribe
  • Linux Manuals
  • Search
SysTutorials
Scripting & Utilities

How to Unignore Files and Directories in Git

ByEric Ma Posted onMar 24, 2018Apr 13, 2026 Updated onApr 13, 2026

Sometimes you have a global gitignore rule—like ignoring all *.log files—but need to track one specific exception. Git lets you negate patterns using the ! character.

# Ignore all log files
*.log

# But DO track this one specific file
!important.log

Pattern matching is evaluated top-to-bottom, and the last matching pattern wins. Your negation rule must come after the pattern it negates, otherwise it won’t work.

Negating directories

To unignore a directory and its contents:

# Ignore all directories named node_modules
node_modules/

# But track this specific one
!vendor/node_modules/

If you’ve ignored a parent directory, you need to un-ignore it first before un-ignoring children:

# Ignore build/ entirely
build/

# Un-ignore the directory itself
!build/

# Now un-ignore specific files within it
!build/important.txt
!build/config/

Unignoring with wildcards

Use ! with glob patterns:

# Ignore all .tmp files
*.tmp

# Except these
!config.tmp
!cache/*.tmp

When files are already tracked

If a file was committed before being added to .gitignore, the ignore pattern won’t remove it from version control—it’ll still appear in git status as modified. Remove it from Git’s index without deleting the local file:

git rm --cached <file>
git commit -m "Stop tracking <file>"

For directories:

git rm -r --cached <directory>/
git commit -m "Stop tracking <directory>"

Testing ignore patterns

Check what Git would ignore without modifying anything:

git check-ignore -v <file-or-pattern>

The -v flag shows which .gitignore rule matched. This is invaluable for debugging why a negation isn’t working.

# Check multiple files
git check-ignore -v *.log

Negation edge cases

Double negation doesn’t work: You can’t un-un-ignore something. !important.log negates the *.log rule, but you can’t add another ! to cancel that out.

Negation in subdirectories: If you’re using a .gitignore in a subdirectory, negation patterns only apply within that directory’s scope.

project/
├── .gitignore          # Rules apply to entire repo
└── src/
    └── .gitignore      # Rules apply only to src/ and below

Performance with many negations: If you’re un-ignoring dozens of files, consider the inverse approach: whitelist what you want to track instead of blacklisting what you don’t.

# Instead of ignoring 50 file types and un-ignoring 10
# Just track what you need:
*
!*.py
!*.yml
!README.md

Alternative: per-repo vs. global ignores

If exceptions are repo-specific, use .gitignore in the repository. For personal rules that apply everywhere (editor temp files, OS junk), use your global gitignore:

git config --global core.excludesfile ~/.gitignore_global

Then add patterns to ~/.gitignore_global. This keeps clutter out of shared .gitignore files.

2026 Best Practices and Advanced Techniques

For How to Unignore Files and Directories in Git, understanding both the fundamentals and modern practices ensures you can work efficiently and avoid common pitfalls. This guide extends the core article with practical advice for 2026 workflows.

Troubleshooting and Debugging

When issues arise, a systematic approach saves time. Start by checking logs for error messages or warnings. Test individual components in isolation before integrating them. Use verbose modes and debug flags to gather more information when standard output is not enough to diagnose the problem.

Performance Optimization

  • Monitor system resources to identify bottlenecks
  • Use caching strategies to reduce redundant computation
  • Keep software updated for security patches and performance improvements
  • Profile code before applying optimizations
  • Use connection pooling and keep-alive for network operations

Security Considerations

Security should be built into workflows from the start. Use strong authentication methods, encrypt sensitive data in transit, and follow the principle of least privilege for access controls. Regular security audits and penetration testing help maintain system integrity.

Related Tools and Commands

These complementary tools expand your capabilities:

  • Monitoring: top, htop, iotop, vmstat for system resources
  • Networking: ping, traceroute, ss, tcpdump for connectivity
  • Files: find, locate, fd for searching; rsync for syncing
  • Logs: journalctl, dmesg, tail -f for real-time monitoring
  • Testing: curl for HTTP requests, nc for ports, openssl for crypto

Integration with Modern Workflows

Consider automation and containerization for consistency across environments. Infrastructure as code tools enable reproducible deployments. CI/CD pipelines automate testing and deployment, reducing human error and speeding up delivery cycles.

Quick Reference

This extended guide covers the topic beyond the original article scope. For specialized needs, refer to official documentation or community resources. Practice in test environments before production deployment.

Post Tags: #Bash#Cache#Editor#Git#How to#OS#performance#Programming#R#Tutorial#www

Post navigation

Previous Previous
Getting File Modification Time in C++ on Linux
NextContinue
How to Check CPU Clock Speed on iPhone

Tutorials

  • Systems & Architecture Academy
    • Advanced Systems Path
    • Security & Cryptography Path
  • Linux & Systems Administration Academy
    • Linux Essentials Path
    • Linux System Administration Path
  • Programming Academy
  • Web3 & Crypto Academy
  • AI Engineering Hub

Categories

  • AI Engineering (4)
  • Algorithms & Data Structures (14)
  • Code Optimization (8)
  • Databases & Storage (11)
  • Design Patterns (4)
  • Design Patterns & Architecture (18)
  • Development Best Practices (104)
  • Functional Programming (4)
  • Languages & Frameworks (97)
  • Linux & Systems Administration (727)
  • Linux Manuals (56,855)
    • Linux Manuals session 1 (13,267)
    • Linux Manuals session 2 (502)
    • Linux Manuals session 3 (32,501)
    • Linux Manuals session 4 (117)
    • Linux Manuals session 5 (1,724)
    • Linux Manuals session 7 (887)
    • Linux Manuals session 8 (4,721)
    • Linux Manuals session 9 (3,136)
  • Linux System Configuration (32)
  • Object-Oriented Programming (4)
  • Programming Languages (131)
  • Scripting & Utilities (65)
  • Security & Encryption (16)
  • Software Architecture (3)
  • System Administration & Cloud (33)
  • Systems & Architecture (46)
  • Testing & DevOps (33)
  • Uncategorized (1)
  • Web Development (25)
  • Web3 & Crypto (1)

SysTutorials, Terms, Privacy

  • SysTutorials
    • Linux & Systems Administration Academy
    • Web3 & Crypto Academy
    • Programming Academy
    • Systems & Architecture Academy
  • Subscribe
  • Linux Manuals
  • Search