List all ignored files in git


Motivation #

Recently, I’ve been working on a project where I, as usual, vendored my Golang dependencies by go mod vendor command. I then added these files to git and pushed them to the remote repository.

However, I noticed that the CI/CD pipeline was failing due to the presence of these files. I was puzzled as to why this was happening. I then realized that some files or directories were being ignored by git, and I had to find out which ones.

The Method #

I was aware of the git status --ignored command, but it didn’t provide the desired output. I wanted to see the list of ignored files and directories, but the command only showed the ignored files that were already tracked by git. I needed to see all ignored files, including the untracked ones.

I then discovered the git ls-files --others --ignored --exclude-standard command, which did exactly what I wanted. It listed all ignored files and directories, including the untracked ones. Where I could then see the files and directories that were being ignored by a .gitignore file generated by gitignore.io.

Epilogue #

In troubleshooting a CI/CD hiccup during Golang dependency vendoring, a routine process led to unexpected complexities. Conventional Git commands fell short, prompting the discovery of git ls-files –others –ignored –exclude-standard. The culprit? A dynamically generated .gitignore from gitignore.io. This incident is a reminder of the dynamic nature of development workflows, where routine tasks can unearth unforeseen challenges, paving the way for continual learning.