Joseph Tura
Joseph Tura

Reputation: 6360

How do I ignore file extensions in git regardless of case?

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?

Upvotes: 51

Views: 18494

Answers (2)

Todd A. Jacobs
Todd A. Jacobs

Reputation: 84443

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.

Upvotes: 20

CharlesB
CharlesB

Reputation: 90496

Git ignore understands glob pattern, so you can use this

*.[jJ][pP][gG]

Upvotes: 76

Related Questions