How to do a case sensitive file rename in git on macOS

2021-03-11 #git

Mac is case insensitive, Linux isn't. This has caused me trouble in the past after deploying my code to an Ubuntu server.

If you rename a file on Mac, git won't pick up any changes if you only change the case.

mv app.js App.js

macOS displays the newly-cased filename, but git doesn't see any changes.

In the past I've worked around this by doing two commits: one to change it to a different filename entirely, and then another to what it should be. app.jsappp.jsApp.js 🤦‍♂️

Turns out there's an easier way: git mv. If you use the git mv command to rename the file, git picks it up correctly.

git mv app.js App.js

That's it. Happy committing!