AZ.dev

List all git-ignored files and folders in a repo

| git: 2.x

Get a flat list of every file and folder git is currently ignoring:

git ls-files --others --ignored --exclude-standard

Why This Command

--exclude-standard tells git to apply the full three-tier ignore stack: .gitignore, .git/info/exclude, and your global gitignore. Skip it and results depend on which exclude sources git happens to consult, so you can end up with an incomplete list.

Alternatives

For a quick look folded into your normal status output:

git status --ignored

Add =matching to expand each ignored directory into every file inside it, instead of collapsing the whole folder to one line:

git status --ignored=matching

Gotchas

Both commands above only report ignored paths that are currently untracked. A file that was committed before it got added to .gitignore stays tracked, and neither command will list it. Find those with:

git ls-files -ci --exclude-standard

Here -c means “cached” (tracked), not “count.” Combined with -i --exclude-standard, it surfaces tracked files that match an ignore rule, which is usually the sign that someone should run git rm --cached on them.

git gitignore ignored-files ls-files status

Was this helpful?

Related Entries

Undo the last commit but keep the changes