Git: Show Ignored Files

A .gitignore file specifies the files that Git should ignore.

Sometimes you may need to list all the files that Git should ignore.

In this short note i will show 2 methods of how to list ignored files in Git.

Show Ignored Files in Git

To show all the ignored files in a Git repository, use the git status command with the --ignored flag:

$ git status --ignored
- sample output -
On branch master
Ignored files:
  (use "git add -f ..." to include in what will be committed)

nothing to commit, working tree clean

The command above is recursively searching for all the .gitignore files in the repository and lists the files matching the patterns to ignore.

Cool Tip: Show Git config settings! Read more →

Another way to list the ignored files is by using the git clean command, that removes untracked files from a working tree:

$ git clean -ndX
- sample output -
Would remove files/latest.tgz
Would remove vault.txt
Option Description
-n, --dry-run Don’t actually remove anything, just show what would be done
-d Remove untracked directories in addition to untracked files.
-X Remove only files ignored by Git.

Cool Tip: Increase VERBOSITY of Git commands! Read more →

Leave a Reply