Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git is ignoring files that aren't in gitignore

Tags:

git

gitignore

People also ask

How do I stop git from ignoring files?

gitignore file will not untrack them -- they will remain tracked by Git . To untrack files, it is necessary to remove from the repository the tracked files listed in . gitignore file. Then re-add them and commit your changes.

Why does .gitignore not work?

Some times, even if you haven't added some files to the repository, git seems to monitor them even after you add them to the . gitignore file. This is a caching issue that can occur and to fix it, you need to clear your cache.

Why do we ignore files in git?

When Do You Use Git Ignore File? The git ignore file rule allows you to ignore a file you've committed in the past. You use it when you do not want to recommit a file, for example a build artifact.

Does git add ignore Gitignore?

The . gitignore file tells Git which files to ignore when committing your project to the GitHub repository. gitignore is located in the root directory of your repo. / will ignore directories with the name.


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.


I had the same problem - a directory was being ignored by git with this error:

➭ git add app/views/admin/tags/
The following paths are ignored by one of your .gitignore files:
app/views/admin/tags
Use -f if you really want to add them.
fatal: no files added

I finally figured out my problem was a line in my ~/.gitignore_global:

TAGS

which was matching the path app/views/admin/tags. I fixed it by adding a leading slash to the global gitignore file

/TAGS

and git started tracking my directory again.