Git: Identifying files that .gitignore is purposely skipping

Because of the inherited nature of .gitignore, it can be tricky to determine if you have any files in your repository folder that are “hiding” from source control without your knowledge.

This may be in the form of files that should be under source control but got caught in a broad inherited .gitignore rule, or may be a log file accidentally created when a script was run.  Either way, you can easily identify these files using either “git status” or “git ls-files”:

# show untracked files and directory names
git status --ignored -s | grep '!!'

# shows all untracked files, including files in untracked directories
git status --ignored -s --untracked-files=all | grep '!!'

# use ls-files to show other untracked files, without hidden folders
git ls-files --others | grep -v '/\.'

REFERENCES

git status man page

git-ls man page