.gitignore
The Filter
The .gitignore file tells Git which files to completely skip over when scanning your working directory. But it has one crucial constraint that catches everyone out: it only works on untracked files.
Live Pattern Matching
Edit the .gitignore on the left and watch the files on the right respond instantly. Pay attention to tracked.log.
.gitignore
Try typing *.log or temp/
Working Directory
How Patterns Work
Git reads .gitignore line by line. Each line is a glob pattern matched against file paths relative to the repo root. The most common patterns are:
*.log— ignore any file ending in.logtemp/— ignore an entire directory namedtempbuild/— ignore anybuilddirectory at any depth/dist— ignore only a top-leveldistdirectory!important.log— un-ignore a specific file that a prior rule caught
The Golden Rule
.gitignore is consulted only when Git scans for untracked files — files that have never been staged or committed. If a file is already in the Index, Git has no reason to consult .gitignore; it already knows about the file.
This is why adding *.log after you accidentally committed a log file does nothing. The fix is to remove the file from tracking first, then add the pattern.
The Fix for Already-Tracked Files
git rm --cached removes a file from the Index (tracking) without deleting it from your disk. After that, .gitignore takes over.