50

I want to tell git to ignore e.g. jpg files regardless of how the extension is written.

e.g.

*.jpg

should ignore

.jpg, .JPG., .Jpg

etc.

Is that possible without telling git to ignore case altogether?

Joseph Tura
  • 6,290
  • 8
  • 47
  • 73

2 Answers2

76

Git ignore understands glob pattern, so you can use this

*.[jJ][pP][gG]
CharlesB
  • 86,532
  • 28
  • 194
  • 218
20

You can tell git to ignore case in most situations, including in your .gitignore files. All you need is:

git config core.ignorecase true

From a practical point of view, there may be trade-offs involved. The git-config(1) man page says:

   core.ignorecase
       If true, this option enables various workarounds to enable git to
       work better on filesystems that are not case sensitive, like FAT.
       For example, if a directory listing finds "makefile" when git
       expects "Makefile", git will assume it is really the same file, and
       continue to remember it as "Makefile".

       The default is false, except git-clone(1) or git-init(1) will probe
       and set core.ignorecase true if appropriate when the repository is
       created.

So, you may run into trouble if you are on a case-sensitive filesystem. Your mileage may vary.

Todd A. Jacobs
  • 81,402
  • 15
  • 141
  • 199
  • 7
    I would not recommend this. First, as you say, this does not only make `.gitconfig` case insensitive, but essentially all of Git. Then, the config is a per-user or per-clone thing, so it won't apply to other co-developers who share `.gitconfig` with you. – Matthieu Moy May 26 '15 at 09:20
  • 2
    I agree with @MatthieuMoy. You will absolutely, definitely, most certainly regret this -- but only after hours of debugging why your files are missing or why everything is mysteriously broken. If this is on, turn it off. – 0942v8653 Jun 06 '16 at 02:26
  • i using win10 and it seems case insensitive. I cant remember to set core.ignorecase in my repo. who can i check this? – SL5net Mar 10 '19 at 07:22
  • as pointed out by @MatthieuMoy this is **not safe** in general but only when us have a case insensitive file system such as on windows. – elonderin May 20 '21 at 10:14
  • NTFS is case-sensitive. Windows isn't. It's a subtle difference. This option is for working on FAT16, which is neither case-sensitive nor case-preserving. Imho, this is the wrong approach – CervEd Jul 01 '21 at 12:21