161

I have a git repository that is ignoring image files as well as a few other files, but my .gitignore file only has it ignoring a config.php file. Is there some global ignore file somewhere that I can't seem to find? I have to specify files to add them now, and it's giving me this warning:

The following paths are ignored by one of your .gitignore files.

The contents of my ~/.gitconfig file are only my e-mail address.

1

15 Answers 15

266

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

6
  • 5
    This is much better than the accepted answer. No offense to that one, but this saved my day. Thank you kenorb.
    – luanjunyi
    Commented Aug 4, 2015 at 21:46
  • 1
    Deserves more upvotes. Found out that some weird gitignore in some /vendor/ folders caused issues with latest git version. Commented Sep 5, 2015 at 20:50
  • 3
    this one saved me today... it seems that visual studio created a file called gitignore_global.txt in the users document folder and this was ignoring files I was not able to (un)ignore
    – Samuel
    Commented Nov 18, 2015 at 23:58
  • 1
    Perfectly solved my problem. Some patterns are not easy to catch by eye!!
    – Willa
    Commented Sep 15, 2016 at 13:27
  • Your answer helped me a lot. I will from now on, have at the top of my gitignore files two comments: # Git is ignoring files that aren't in gitignore followed by the URL to this answer.
    – Karl
    Commented Nov 13, 2021 at 12:04
58

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).

6
  • 2
    This was indeed my problem. Not sure how or when this file is edited but it had the file I wanted listed in it
    – toxaq
    Commented Feb 26, 2014 at 6:06
  • 3
    Thank you, you saved me hours of pure agony. In my case, it was the installation of source tree(a tool visualize git repo) which unlogically created under documents folder a gitignore_global.txt which included plenty of exclusions. Commented Nov 27, 2014 at 23:58
  • I had that same damn Icon? being ignored. Commented Dec 10, 2015 at 1:25
  • This was the case for me. Had quite a few rules inside the global ignore file. Thanks for the tip +1
    – Madness
    Commented Oct 4, 2016 at 10:23
  • I had *.json in my global ignore - talk about a nightmare - thank you! Commented Jan 2, 2020 at 15:10
34

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.

3
  • There are no other .gitignore files in the repository, nor is there anything in the .git/config file that ignores anything. How is .git/info/exclude configured?
    – Ian Hunter
    Commented Feb 24, 2012 at 19:13
  • 4
    It's not clear why this answer is marked as answered. How exactly this issue was resolved? Commented Aug 15, 2016 at 15:51
  • exclude was my problem. I knew there was another way to ignore, which I'd used in the past, but forgotten where it was! Commented Jun 14, 2017 at 9:05
23

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.

4
  • 3
    +1 for making me look for partial matches... gitignore_global.txt contained "[Rr]elease*/" which was causing my "releasenotes" directory to be ignored.
    – Trev
    Commented May 2, 2013 at 2:09
  • To make it even harder, git will ignore only newly-added files, not ones already in the repo. So when I added "foo/" to my .gitignore, it ignored only recently added files in foo subdirectories and not all files. Took me an hour to figure out why some files were being ignored and others weren't.
    – ccleve
    Commented Jan 9, 2015 at 18:10
  • I have the same problem. SourceTree sets ~/.gitignore_global file in Tools menu->Options item-> Git tab. After I cleaned up field Global Ignore list "git add..." command worked.
    – Kate
    Commented Feb 29, 2016 at 12:21
  • I had the same issue. I had help directory which was being ignored. Luckily I found your answer quite quickly. Commented Sep 24, 2018 at 10:31
11

For me I accidentally had a wildcard in my ~/.gitignore_global file. Maybe check there?

1
  • 1
    That was exactly the issue for me. I had *.png there, no idea how it got there.
    – Shahar
    Commented Jan 26, 2016 at 9:37
3

Another thing to try: I had a directory B with its own .git repository nested under my project directory A (but not as a submodule). I made some changes to B, and wanted to make it into a bonafide submodule. I believe git A was automatically ignoring B because it contained its own repository (see Nested git repositories without submodules?). I renamed the B folder, and tried to clone it again as a submodule, and that was bringing me the misleading "ignored by .gitignore" error message. The solution was to delete .git out of B.

3

In my case it was the forward slash in my path causing the problem...

Not Work

/srv/bootstrap/

Work

srv/bootstrap/
3

It may not be .gitignore: skip-worktree and assume-unchanged

A file may be ignored for the following reasons:

  1. .gitignore (the combination of all of them)
  2. git update-index --skip-worktree
  3. git update-index --assume-unchanged

Additionally, a file may be UNignored by if it is in .gitignore AND already staged in the index/cache.

To check for the enumerated cases above:

  1. For the two cases of .gitignore excludes, compare the output of:

    • git check-ignore --verbose --non-matching --no-index file1 file2 file3
    • git check-ignore --verbose --non-matching file1 file2 file3
  2. git ls-files file1 file2 file3 | grep -E '^S'

  3. git ls-files file1 file2 file3 | grep -E '^[[:lower:]]'

That's too hard, just give me an alias!

The following aliases will cover all the cases listed above:

ignore = !"bash -c 'diff --unified=999999999 --color=always <(echo a; git check-ignore --verbose --non-matching --no-index . \"$@\") <(echo b; git check-ignore --verbose --non-matching . \"$@\")' - \"$@\" | tail -n+7; git hidden \"$@\" # Show ignore status of arguments. Files included by index are tagged with prepended '+'."
hidden = !"git ls-files -v -- \"$@\"| grep -E '^(S|[[:lower:]])' # S means update-index --skip-worktree, and lower first letter means --assume-unchanged."

The comment and final " are part of the line to be copied to your .gitconfig.

Usage:

git ignore file1 file2 file3
2

I was having the exact same problem as you. The only reply you got listed a few places to check, but none of them solved the problem for me, and from your comment I don't think for you either. I had no OTHER .gitignore files hiding lower in the directory tree; nothing in .git/config; nothing in .git/ingore/exclude

If you still have the problem, check this answer. It solved the issue for me

Basically, check for a ~/.gitignore file. Mine was called ~/.gitignore_global. I don't know when it was created (I certainly didn't make it), but I tried a ton of different git setup's when I first installed, so one of them must have put it there.

Hope his answer helps you as well!

1

Another reason for receiving this error message from git is when executing the git submodule add command while a previous git command has crashed and left the lock file (this can happen, for instance, when you use custom scripts which include git commands and you haven't noted the crash).

If you execute the command git commit instead, while none of the conditions have changed (git submodule add will keep yelling that your .gitignore files are to blame), you'll see another error report instead:

$ git commit -a
fatal: Unable to create '..../.git/index.lock': File exists.

If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.

and indeed deleting the lockfile:

rm .git/index.lock

resolves the issue. (This happens to git version 2.1.0.9736. It may be fixed in future git releases.)

1
  • Thanks this turned out to be the issue I was having. Life saver!
    – JDawgg
    Commented Mar 16, 2017 at 3:21
1

Check you have permission to the folder. I have just run into this and it was because the folder was owned by the www-data user not the user I was logged in to the terminal as.

1

One more thing: if the directory you're in requires root access for writing or executing, make sure you're on the root user. I actually got a weird error where I was trying to add a submodule and git kept complaining that the path I was cloning into was being ignored by a git ignore file. Then I changed to root user, ran the submodule add again, and there was no problem.

0

Please also check ~/.gitignore and ~/.gitignore_global which might be created by some Git clients (e.g. Atlassian SourceTree on Mac OS X).

0

Make sure the .gitignore file is not ignoring itself. A common mistake is adding a * rule to the .gitignore file to ignore every file in the current folder. The solution to this is to add an exception to .gitignore:

*
!.gitignore

This way all files in the directory will be ignored, except .gitignore.

0

Check if you are on the right branch.

Not the answer you're looking for? Browse other questions tagged or ask your own question.