Git is ignoring files that aren't in gitignore

git check-ignore

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

For 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 HOME and repository folder:

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

Alternatively use git add -f which allows adding otherwise ignored files.

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

Syntax

git check-ignore [options] pathname…​

git check-ignore [options] --stdin


It might be good to know that your git configuration can contain a core.excludesfile which is a path to a file with additional patterns that are ignored. You can find out if you have such a configuration by running (in the problematic git repo):

git config core.excludesfile

If it prints a file path, look at the contents of that file for further information.

In my case I installed git via an old version of boxen which ignored the pattern 'Icon?' that in my case gave me the warning, mentioned in this question, for a folder icons (I'm on a case insensitive filesystem that's why Icon? matches icons).


Check these out:

  1. Have you looked for other .gitignore files, as there can be many of them.

  2. Also, look at REPO/.git/config to see if there is anything there.

  3. Repo exclude Local per-repo rules can be added to the .git/info/exclude file in your repo. These rules are not committed with the repo so they are not shared with others. This method can be used for locally-generated files that you don’t expect other users to generate, like files created by your editor.

Tags:

Git

Gitignore