Commit a case-only filename change in Git

Record filename capitalization changes reliably, preserve a single commit, and avoid misconfiguring Git for a case-insensitive filesystem.

Best practices
Illustration of Git branches and version history

On a case-insensitive filesystem, changing myfile.txt to MyFile.txt outside Git may not appear as the rename you expect. Use git mv so the index records the intended spelling:

git mv -- myfile.txt MyFile.txt
git diff --cached --summary
git commit -m "Capitalize MyFile filename"

The behavior depends on the filesystem and Git configuration, not simply on whether you run Windows, macOS, or Linux. Windows and macOS commonly use case-insensitive filesystems, but exceptions exist.

Use an intermediate name if needed

If a direct case-only move fails, choose a temporary path that does not already exist:

git mv -- myfile.txt rename-intermediate.txt
git mv -- rename-intermediate.txt MyFile.txt
git diff --cached --summary
git commit -m "Capitalize MyFile filename"

Both moves can be made before a single commit; an extra “temporary rename” commit is unnecessary. The same approach works for directories. Update import statements, links, and resource paths to match the final spelling before committing.

Git stores snapshots and generally detects renames by comparing them. git mv updates the working tree and index; it does not create a special rename object in history.

Keep core.ignoreCase consistent with the filesystem

Git probes filesystem behavior during initialization or cloning and may set core.ignoreCase accordingly. Setting it to false does not make a case-insensitive filesystem capable of storing two colliding paths. Git's documentation warns that changing it incorrectly can cause unexpected behavior.

Prefer explicit moves to treating this setting as a global fix. If the repository already contains both README.md and Readme.md, resolve the collision on a filesystem that can represent both, then commit a naming scheme usable by your team.

Detect possible collisions

For a quick check of ordinary filenames:

git ls-files | sort -f | uniq -di

This reports a representative of a case-insensitive duplicate group; it does not print every pair. It is line-based, locale-dependent, and not reliable for arbitrary filenames containing newlines. For an automated repository audit, process git ls-files -z and choose normalization rules appropriate to the target filesystem. Case folding alone may not model all filesystem Unicode rules.

Why does CI fail when the local build works?

A case-sensitive CI filesystem may reject import "./myfile" after the tracked path became MyFile. Match the repository spelling exactly, including directories. A consistent convention such as lowercase names with hyphens can prevent many collisions, provided it fits the project's language and framework conventions.

See git-mv and core.ignoreCase.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting