The .gitignore
file is a file where you can list files that should be ignored
by git. This will prevent them from showing up in diffs, git status
, etc.
Most entries in the .gitignore
file will plainly correspond to a single file.
# ignore env var files
.env
.env.local
Sometimes a project has a bunch of similarly named files. Autogenerated files
are a prime example. For instance, a web app project may contain several
sitemap files with incrementing suffix values (i.e. sitemap-1.xml
,
sitemap-2.xml
, sitemap-3.xml
, ...).
I'd like to avoid having to type those all out in my .gitignore
file. And I
don't want to have to add new entries whenever another increment of the file is
generated.
I can handle all the current ones and future ones in a single line using some
range pattern matching supported by the .gitignore
file format.
# ignore sitemap files
public/sitemap-[1-99].xml
This will ignore any sitemap files suffixed with 1 to 99. I don't really expect there to ever be more than handful of those files, so 99 should definitely do the trick.