Gitignore Awareness
Like rg, ag reads ignore files before traversing directories, skipping excluded paths entirely.
Files ag Respects (in priority order)
| File | Scope |
|---|---|
.agignore | ag-specific, highest priority |
.ignore | Shared ignore rules |
.gitignore | Git exclusions |
.hgignore | Mercurial exclusions |
What Gets Skipped Automatically
In a typical Node.js project, ag "axios" skips:
node_modules/(listed in.gitignore)dist/,build/,.cache/.git/(hidden directory)- Any binary files (auto-detected)
This makes ag "axios" return only your source code results in milliseconds.
Verifying What Gets Searched
# List all files ag would search (without actually searching)
ag -l ""
# With debugging — shows why files are skipped
ag --debug "pattern" 2>&1 | grep -i "skip\|ignor" | head -20
Overriding Ignore Rules
# Don't respect .gitignore
ag --skip-vcs-ignores "pattern"
# Search hidden dotfiles too
ag --hidden "pattern"
# Search EVERYTHING (like find)
ag -u "pattern" # or --unrestricted
# Search everything twice (completely unrestricted)
ag -uu "pattern"
The -u / --unrestricted ladder:
| Flag | Effect |
|---|---|
| (default) | Respects all ignore files, skips hidden |
-u | Ignores .gitignore etc., still skips hidden |
-uu | Ignores all ignore files AND searches hidden files |