How to check what is being ignored in your local git repository using command line

Sunday, June 21, 2026 at 5:02 AM | 3 min read

Last modified on Sunday, June 21, 2026 at 5:11 AM

#macOS, #command line, #git, #gitignore

Large sign with the words "Error: No Content" against a dark forbidding sky

Photo by Alexander Grigoryev on unsplash.com

Table of Contents

The other day, I git cloned one of my remote Git repositories, created some new files that I populated and then added to the .gitignore file. Later, I created another clone, and forgot to copy over the contents of the newly ignored files. It prompted me to create a command which would check for ignored files in my local Git repository as well as making sure they actually existed in the repository.

How to check what is being ignored in a local Git repository using the git status command

In order to both find out what is being ignored in my local Git repository as well as making sure the ignored items actually exist in the repository, I can run the following command in Terminal:

git status --ignored

For me, the following was returned:

git status --ignored On branch how-to-check-what-is-being-ignored-in-your-local-git-repository-using-command-line Untracked files: (use "git add <file>..." to include in what will be committed) data/blog/how-to-check-what-is-being-ignored-in-your-local-git-repository-using-command-line.mdx public/images/blog/how-to-check-what-is-being-ignored-in-your-local-git-repository-using-command-line/ Ignored files: (use "git add -f <file>..." to include in what will be committed) .DS_Store .husky/_/ .next/ data/.DS_Store deleted-posts.txt git-status-output.txt node_modules/ output.txt

This is all well and good, but how do I know that this command is returning both what is being ignored in the .gitignore file and also exists in the repository?

I deleted the empty output.txt file and then ran the same command again. This time, the stdout was:

git status --ignored On branch how-to-check-what-is-being-ignored-in-your-local-git-repository-using-command-line Untracked files: (use "git add <file>..." to include in what will be committed) data/blog/how-to-check-what-is-being-ignored-in-your-local-git-repository-using-command-line.mdx public/images/blog/how-to-check-what-is-being-ignored-in-your-local-git-repository-using-command-line/ Ignored files: (use "git add -f <file>..." to include in what will be committed) .DS_Store .husky/_/ .next/ data/.DS_Store deleted-posts.txt git-status-output.txt node_modules/

This time, output.txt was not returned, but it still was added to the .gitignore file. This confirmed that when a file which has been added to the .gitignore file is removed from the repository, it will not be included among the ignored files returned from the git status --ignored command. Next time, I will make sure to run this command as part of my workflow when cloning a remote repository which does not contain files ignored by Git. I will also make sure that I don't delete the other copy containing said files until I have double-checked their existence in the newer copy of the repository.

The meaning of the git status --ignored command and what it actually does

But what does the git status --ignored command really mean? What does it actually do?

In this case, the git status command returns all the tracked items in the Git repository that have changes since the last commit. There were no staged or modified tracked files yet — just the untracked and ignored items shown above.

The --ignored flag recursively1 searches for all the .gitignore files in the repository and lists the files matching the patterns to ignore according to the .gitignore file. That's why a file that has been added to .gitignore, and is then deleted, is not included in the output of git status --ignored.

Conclusion

Recently, I found that I can check whether files ignored by Git actually exist within the Git repository by running the git status --ignored command. I am adding it to my Git workflow so that data stored in such ignored files is never lost.

Footnotes

  1. In command line terms, recursively means the git status --ignored command impacts the whole root directory of the git repository and its subdirectories looking for more .gitignore files to apply.