Changing capitalization of filenames in Git

I am trying to rename a file to have different capitalization from what it had before:

git mv src/collision/b2AABB.js src/collision/B2AABB.js
fatal: destination exists, source=src/collision/b2AABB.js, destination=src/collision/B2AABB.js

As you can see, Git throws a fit over this. I tried renaming using just the plain old mv command as well, but Git doesn't pick up the rename (as a rename or as a new untracked file).

How can I change a file to have a different capitalization of the same name? I am on Mac OS X v10.7.3 (Lion) with Git 1.7.9.1 using Z shell (zsh) 4.3.15.


Starting Git 2.0.1 (June 25th, 2014), a git mv will just work on a case-insensitive OS.

See commit baa37bf by David Turner (dturner-tw).

mv: allow renaming to fix case on case-insensitive filesystems

"git mv hello.txt Hello.txt" on a case-insensitive filesystem always triggers "destination already exists" error, because these two names refer to the same path from the filesystem's point of view and requires the user to give "--force" when correcting the case of the path recorded in the index and in the next commit.

Detect this case and allow it without requiring "--force".

git mv hello.txt Hello.txt just works (no --force required anymore).


The other alternative is:

git config --global core.ignorecase false

And rename the file directly; git add and commit.

It does work in a CMD. It might fail in a git bash (on Windows) session (see Louis-Caron's answer)

As noted by jaquinocode in the comments, if your local repository itself has that setting:

git config --local core.ignorecase false

Considering larsks' answer, you can get it working with a single command with "--force":

 git mv --force myfile MyFile

Sometimes you want to change the capitalization of a lot of file names on a case insensitive filesystem (e.g. on macOS or Windows). Doing individual git mv commands will tire quickly. To make things a bit easier this is what I do:

  1. Move all affected files outside of the directory to, let’s say, the desktop.
  2. Do a git add . -A to stage the removal of those files.
  3. Rename all files on the desktop to the proper capitalization.
  4. Move all the files back to the original directory.
  5. Do a git add .. Git should see that the files are renamed.

Now you can make a commit saying you have changed the file name capitalization.


File names under OS X are not case sensitive (by default). This is more of an OS problem than a Git problem. If you remove and readd the file, you should get what you want, or rename it to something else and then rename it back.