The Problem
Today I ran into a frustrating Git issue that I’d never encountered before. I had renamed several image files in my Obsidian vault’s _attachments
folder, changing their extensions from uppercase (.PNG
, .JPG
, .WEBP
) to lowercase (.png
, .jpg
, .webp
).
However, when I tried the usual workflow:
git add .git commit -m "Fix file extensions"git push
Git didn’t detect any changes, even though I could clearly see the files had different extensions on my filesystem.
The Root Cause
The issue stems from macOS having a case-insensitive filesystem while Git is case-sensitive.
From the filesystem’s point of view, image.PNG
and image.png
are the same file, but Git sees them as different files.
This caused a mismatch where Git was still tracking the old uppercase extensions in its index, even though the filesystem only showed the lowercase files.
As a result, Git doesn’t realize the file has been renamed because the filesystem treats both names as identical.
The Solution: git mv
The solution is to use git mv
to explicitly tell Git about the change. The git mv
command renames the file both in your filesystem and Git’s index, so Git can track the rename as a single operation:
# Instead of manually renaming files, use git mvgit mv oldfile.PNG newfile.pnggit mv image.JPG image.jpggit mv photo.WEBP photo.webp
What I Did
I had to rename several files that Git was tracking with uppercase extensions:
cd "/path/to/my/repo"
# First, find out which files with uppercase extensions Git is trackinggit ls-files _attachments/ | grep -E "\.(PNG|JPG|WEBP)$"
# Then rename each one using git mvgit mv _attachments/2b3a6c702b5b01cf12507cc029630bf3.JPG _attachments/2b3a6c702b5b01cf12507cc029630bf3.jpggit mv _attachments/316d587a5c95f54ea7a4f86fbb986d63.PNG _attachments/316d587a5c95f54ea7a4f86fbb986d63.pnggit mv _attachments/33fabea8972383bcb4bbeea50437f690.PNG _attachments/33fabea8972383bcb4bbeea50437f690.png# more attachments...
# Commit the changesgit commit -m "Rename image file extensions from uppercase to lowercase"git push
Alternative Solutions
Other approaches I could have used (but git mv
is cleanest and simplest):
-
Configure Git to ignore case (not recommended):
Terminal window git config core.ignorecase false -
Remove and re-add (loses history):
Terminal window git rm file.PNGgit add file.pngIn contrast, when you use
git mv
, Git properly records the change as a rename:Terminal window # Git status showed:renamed: _attachments/image.PNG -> _attachments/image.png