Developers nowadays use git on many different operating systems – mostly Linux, Windows or macOS. Depending on the filesystem in use, there is a difference in how the casing of file and folder names is handled. While Linux for example is case-sensitive, Windows and macOS are not [1]. So, what to do if you are running Windows and want to rename a file being tracked by git from Main.c to main.c?
git mv -f Main.c main.c
This simple command will enforce a rename of the file on case-insensitive filesystems to make git understand and track it. Note that in order to rename a directory on a case-insensitive file system e.g. from Main to main, you’d have to use the intermediary step
git mv Main temp
git mv temp main
There is also the core.ignoreCase
config effectively telling git how to treat the files in your repository regarding to case. The documentation
states that
[…] the default is false, except git-clone[…] or git-init[…] will probe and set core.ignoreCase true if appropriate when the repository is created.
That means, if a repository is created on a case-insensitive filesystem like in Windows this option will automatically be initialized to true and developers under Linux have to adjust and vice versa. In general, you should make sure that core.ignoreCase matches your system, otherwise errors may occur on some git operations.
Bonus
Since Windows 10 1803 there is an option to enable case-sensitive file and folder names on NTFS for specific directories. Furthermore, Apple’s APFS as well as EXT4 since Linux Kernel version 5.2 support the option to choose whether the file system should be case-sensitive or case-insensitive.
[1] To be precise here, casing is determined by the filesystem, not the OS. I will use the term Windows here as a representative for default NTFS, respectively macOS for default APFS and Linux for default EXT4.