Great question! Besides the basic asterisk *, Git uses several other "glob" patterns to help you match files precisely.
Here are the most common wildcard patterns you can use in your .gitignore:
1. The Single Asterisk (*)
Matches zero or more characters within a single directory level.
*.txtmatchesnotes.txtandtodo.txt.res*matchesresults.txtorresources/.
2. The Double Asterisk (**)
Matches directories recursively (at any depth).
**/logs/matches a directory namedlogsanywhere in the project (e.g.,logs/,scripts/logs/, orsrc/assets/logs/).docs/**/*.pdfmatches all PDF files inside thedocsfolder and any of its subfolders.
3. The Question Mark (?)
Matches exactly one character.
file?.txtmatchesfile1.txtorfileA.txt, but it will not matchfile10.txt.
4. Square Brackets ([ ])
Matches a single character from a specific set.
temp[0-9].txtmatchestemp0.txtthroughtemp9.txt.data[ab].csvmatchesdataa.csvanddatab.csv, but notdatac.csv.
5. Range within Brackets ([ - ])
Used inside square brackets to define a range.
[a-z].logmatches any single lowercase letter log file.
Summary Table:
| Pattern | Meaning | Example |
|---|---|---|
* |
Zero or more characters | *.log |
? |
Exactly one character | test?.py |
[abc] |
Any one character inside brackets | v[123].js |
** |
Nested directories | **/output/ |
In your current lab, you've used the most common one (*). As your projects grow more complex, these other patterns will help you keep your repository clean