3.2. Pattern Syntax#
The .gitignore file uses glob patterns to match files and directories.
These patterns are similar to, but not exactly the same as, regular expressions.
Pattern scope starts at the directory containing this .gitignore.
Basic Pattern Rules
*.logMatches names ending with .log beside this .gitignore or in its descendants.
error.log, debug.log, logs/app.log
temp.txtMatches the name temp.txt beside this .gitignore or in its descendants.
temp.txt ✅, subdir/temp.txt ✅
/build/Matches a directory named build directly beside this .gitignore, not deeper down.
build/ ✅, src/build/ ❌
build/Matches directories named build at any depth within this .gitignore’s scope.
build/, src/build/, docs/build/ ✅
*.log
!important.log
Ignores .log names within scope, except names exactly important.log, including in descendants.
/*
!/.gitignore
!/src/
Ignores other entries directly beside this .gitignore, but keeps the ignore
file itself and files under src/ eligible for adding.
*.js
!*.test.js
!config.js
Ignores all .js files except test files and config.js