Case-only renaming with Git

Case-only renaming with Git

A case-only rename of a file (eg. => can turn out to be very annoying. If all developers working on your codebase use a case sensitive file system, stop reading and celebrate. Case-only renames are like any other rename and you’ll be fine.

At Procurios, most developers either use a Linux distribution or a Mac (OS X). By default, OS X operates using a case insensitive file system. A seemingly simple rename of TimeLine.php to Timeline.php might give you more issues than you’d expect.

The underlying issue of performing a rename on a case insensitive file system is that the Git status remains the same after the rename. Most of the Git commands won’t work with the new name, because the index still contains the old name.

We’ve had situations where files were duplicated, even though on OS X this wasn’t visible. On Linux you’d see the duplicate files, and notice that the changes are spread across the original and renamed files. This can be very tough to fix if you’re late at catching what was going on.

Turns out that there’s an easy fix. Use git mv --force TimeLine.php Timeline.php to perform a case-only rename. The force flag renames a file even if the target exists. No matter what file system you use, this will force Git to record the rename as a change and record it to the index.

You might have heard of Git’s ignorecase flag that seems to get Git to recognize case-only changes. Don’t use it. It’s a workaround that fails. For example, after renaming file.js to File.js, I executed git status just to see that Git recorded that File.js has been added, without removing file.js. Unreliable to say the least.

Another option is to create a case sensitive file system on your Mac (using Disk Utility). Use that file system for your codebase and you’ll be fine. Some developers suggest to use a microSD card (formatted as case sensitive, journaled) to store their Git projects. I might give that a try whenever (release them already!) those new MacBooks arrive :)

Leave a comment...

Leave a comment

Italic en bold

*Dit is italic*, en _dit ook_.
**Dit is bold**, en __dit ook__.


Dit is een link naar [Procurios](


Een lijst met bullets kan worden gemaakt met:
- Min-tekens,
+ Plus-tekens,
* Of een asterisk.

Een genummerde lijst kan worden gemaakt met:
1. Lijst-item nummer 1.
2. Lijst-item nummer 2.


Onderstaande tekst vormt een quote:
> Dit is de eerste regel.
> Dit is de tweede regel.


Er kan een blok met code worden geplaatst. Door voor de tekst vier spaties te plaatsen, ontstaat een code-block.