thoughtasylumTOOLBOX Preview Guides Use offline Automate Feedback

Guides › Developer

Why is Git ignoring my file (or not ignoring it)?

A file you need doesn’t show up in git status, or a folder of build output you meant to hide keeps appearing. Either way the .gitignore looks right, and Git doesn’t say which line is responsible. These tools test the patterns against the paths in your browser and explain each result, so you can fix the file without trial and error.

1. Find the pattern that decides it

Paste the .gitignore into the Git Ignore Tester and list the paths that behave oddly, one a line, written from the folder the .gitignore is in. End a folder with /, such as build/, as patterns ending in / only match folders. Each path is marked Ignored or Not ignored, with the deciding line and why.

Three details catch most people out:

  • The last matching line wins. !important.log only rescues the file if it comes after *.log.
  • A / anchors a pattern. /config.json and docs/*.pdf match from the .gitignore’s folder; config.json with no / matches a file of that name in any folder.
  • * stops at a folder. docs/*.pdf misses docs/2026/report.pdf; docs/**/*.pdf matches at any depth.

On a Mac or Windows, tick Ignore upper and lower case, as Git does there by default. In a real repository, git check-ignore -v <path> names the file and line that ignores a path, including .gitignore files in sub-folders and your global excludes file, which the tester doesn’t see.

2. Bring back a file inside an ignored folder

A common surprise: with build/ on one line and !build/keep.txt below it, build/keep.txt stays ignored. Once a folder is ignored, Git never looks inside it, so nothing later can bring back a file in it. The tester says so in the Why column.

Ignore the folder’s contents instead of the folder, then make the exception:

build/*
!build/keep.txt

For a file deeper down, each folder on the way has to be let back in too (!build/assets/, then build/assets/*, then the file).

3. Ignored, but Git still shows changes

A .gitignore only affects files Git isn’t already tracking. If .env or node_modules/ was committed before the pattern was added, Git keeps tracking it and the tester’s Ignored makes no difference. Remove it from the repository while keeping your copy with git rm --cached .env (add -r for a folder), then commit. If it held passwords or keys, they’re still in the history: change them.

4. Characters you can’t see

A pattern copied from a web page or chat may carry a non-breaking space in place of a plain one, and Git then looks for that character in the name. The Git Ignore Tester warns about such lines; retype them. Spaces at the end of a line are dropped by Git, so name matches name.

If a file name itself looks right but won’t match, paste the name from the terminal and the pattern into the Character Inspector, one in Text and one in Compare with other text. It says where they first differ and shows hidden spaces, look-alike letters and accents stored a different way.

All 62 guides, grouped by what they help with.

Saved you a few minutes? Say thanks with a coffee.

Something wrong or unclear in this guide? Report it or suggest a guide.

↑ ↓ move↵ openesc close