Git is not detecting a file and is not in .gitignore

I have a file called "style.css" and git is not detecting it. It doesn't detect it if I delete it either, but it does detect if I change the name of the file. But I need it with that name. The file is not in the .gitignore file. This is driving me crazy!

I would appreciate some help.


Use git check-ignore command to debug your gitignore file (exclude files).

In example:

$ git check-ignore -v config.php
.gitignore:2:src    config.php

The above output details about the matching pattern (if any) for each given pathname (including line).

So maybe your file extension is not ignored, but the whole directory.

The returned format is:

<source> <COLON> <linenum> <COLON> <pattern> <HT> <pathname>

Or use the following command to print your .gitignore in user and repo folder:

cat ~/.gitignore $(git rev-parse --show-toplevel)/.gitignore $(git rev-parse --show-toplevel)/.git/info/exclude

Alternatively use git add -f <path/file> which allows adding otherwise ignored files.

See: man gitignore, man git-check-ignore for more details.


Another note, probably a rare case but I had this problem. I moved some files that were already tied to a repo from one directory to another, copy/paste style.

Along with it came the .git folder, which prevented git from detecting the folder.

So my folder structure was this, with git not detecting Folder 2 even though the repo was set for Original Project 1:

--Original Project 1
    --.git
    --Folder 1
    --Folder 2
         --.git
         --Many other files/folders

Deleting the child .git folder solved my problem.


The file could also be listed in .git/info/exclude, and there’s the option core.excludesfile to watch, too.


Apart from the the gitignore and other places to check for ignore patterns, check if you had run git update-index --assume-unchanged or git update-index --skip-worktree. If so, unset them.

Make sure that there is not some weirdness in the repo or parent of the file under concern whereby it has a .git of its own.

Try doing a clone of your repo and see if you see the same in the cloned one. If so, try cloning onto a different machine / VM and check. That will give you some idea of what's going wrong where.