Fix case-sensitive paths on a case-insensitive filesystem on macOS

Fix case-sensitive paths on a case-insensitive filesystem on macOS

Git is case-sensitive, whereas many operating systems like Windows and macOS (despite being Unix) are not. That causes problems when working with a Git repository that contains files with the same names but different casing. You get the following paths have collided (e.g. case-sensitive paths on a case-insensitive filesystem) and only one from the same colliding group is in the working tree warning. The odd part is you can’t also get rid of the unstaged files by checking out or stashing them simply. That effectively renders rebasing useless. In this article, we cover how to fix case-sensitive paths on a case-insensitive filesystem issue on macOS without formatting the partition and going through any tedious process.

The macOS default APFS file system is case-insensitive

The problem is the default APFS file system is case-insensitive, despite macOS being a Unix operating system. One not so convenient fix, yet permanent, is to format your system and use APFS (Case-sensitive, Encrypted), more here. But that’s a time-consuming process. It requires backing up all data, installing apps again, and jumping through many hoops.

Of course, there’s a better and less time-intensive approach to work around the issue discussed in the next section.

Leveraging on Disk Image to workaround macOS APFS case-insensitivity

To have your cake (not formatting your macOS) and eat it too (working with case-sensitive Git repositories), you need to work around the issue using Disk Images. The approach is straightforward. You create a case-sensitive Disk Image on a case-insensitive file system and then work with problematic repositories there.

To create a Disk Image, open the Disk Utility and create a Disk Image by going to File -> New Image -> Blank Image.

Fix case-sensitive paths on a case-insensitive filesystem on macOS

Make sure you’ve selected Mac OS Extended (Case-sensitive, Journaled).

Just mount your image like any other image and then clone the case-sensitive Git repository there. After that, do a git status. The problem should be gone. You shouldn’t get fix case-sensitive paths on a case-insensitive filesystem warning on your macOS anymore.

Recommendation – fix your Git repository

If you are a maintainer of a repository that contains files with the same names but different casing, please do everyone a favor and fix the issue on Git by renaming files.

Although Git allows that, it’s discouraged to have files with the same names.

Inline/featured images credits