How ripgrep Handles Ignored Files
ripgrep skips paths matched by .gitignore, .ignore, or .rgignore, skips hidden dotfiles, and stops at binary files by default, while grep -r searches all of them. Use rg --files -uu, --no-ignore, --hidden, or -a to find out which filter is hiding the file.
The short answer
ripgrep applies three filters before it reads file contents: ignore rules (.gitignore, .ignore, .rgignore), the hidden-file rule (names starting with .), and binary detection (a NUL byte). grep -r performs no equivalent filtering, so a file it reports can be missing from rg's ordinary output without any error or warning.
| Filter | Default in rg |
Lift it with |
|---|---|---|
| Ignore files | Matching paths skipped | --no-ignore |
| Hidden paths | Skipped | --hidden |
| Binary files | No line output | -a or --text |
| Symlinks | Not followed | -L or --follow |
A minimal example
mkdir repo && cd repo
git init -q
printf '*.log\nbuild/\n' > .gitignore
mkdir build
printf 'needle\n' > build/out.txt
printf 'needle\n' > app.log
printf 'needle\n' > keep.txt
rg needle
# keep.txt:needle
grep -r needle .
# ./keep.txt:needle
# ./app.log:needle
# ./build/out.txt:needle
rg honors the ignore file, so both matches disappear. grep -r reads every readable file and reports all three.
A hidden file such as .env is ignored even when no ignore file mentions it, because its name begins with a dot. Ignore rules decide what ripgrep searches; they do not decide what Git commits, a separate comparison covered in staged and unstaged changes.
Which ignore files apply
| File | Scope | Disable with |
|---|---|---|
.rgignore |
Any directory; highest precedence | --no-ignore-dot |
.ignore |
Any directory | --no-ignore-dot |
.gitignore |
Only inside a Git repository | --no-ignore-vcs |
.git/info/exclude |
One repository | --no-ignore-exclude |
| Global Git excludes | Per user, from core.excludesFile |
--no-ignore-global |
Rules nest: a pattern in a deeper directory overrides the same pattern in a parent, and within one file a later line overrides an earlier one. A leading ! re-includes a path. Patterns follow Git's gitignore syntax, where a trailing slash matches directories only and ** spans directories.
.gitignore is consulted only when ripgrep detects a Git repository. Outside one, .gitignore has no effect, while .ignore and .rgignore still apply. --no-require-git relaxes the repository requirement.
--no-ignore is the broad switch: it implies the individual --no-ignore-vcs, --no-ignore-dot, --no-ignore-global, --no-ignore-exclude, and --no-ignore-parent options. Reach for the narrower flag when you want to test one rule at a time.
Hidden files and binaries
A path is hidden when its name starts with a dot. --hidden includes those paths, but it does not cancel ignore rules: a hidden directory matched by an ignore pattern remains excluded. Note that --no-ignore alone still skips .env.
Binary detection is heuristic. ripgrep looks for a NUL byte; once it sees one, it stops treating the file as text. A match may be reported as a binary match rather than printed as a line, and a match after the NUL byte is never shown. -a (or --text) removes the detection and prints matching lines. --binary searches binary files but suppresses their raw bytes and reports only whether a match exists, which is useful for existence checks.
The -u flag is cumulative:
| Flag | Equivalent |
|---|---|
-u |
--no-ignore |
-uu |
--no-ignore --hidden |
-uuu |
--no-ignore --hidden --binary |
Practical checks
List the candidate files instead of guessing: rg --files prints what directory traversal would consider. Compare it with rg --files -uu to see what was removed.
rg --debug pattern logs why paths are skipped, including which ignore rule matched. When you need to confirm a specific file, pass it by name; a file given explicitly is searched even when directory traversal would have excluded it.
To widen a failed search gradually:
rg pattern # normal project search
rg --no-ignore pattern # ignore rules off, hidden still off
rg --no-ignore --hidden pattern
rg -uuu pattern # also search binary files
If a result still differs from grep, check whether the path is reachable only through a symlink, which rg does not follow unless you pass -L.
Sources
Revision history
- Published
- Updated
- — Initial publication.