I have changed a few files name by de-capitalize the first letter, as in Name.jpg to name.jpg. Git does not recognize this changes and I had to delete the files and upload them again. Is there a way that Git can be case-sensitive when checking for changes in file names? I have not made any changes to the file itself.

14 Answers 14


You can use git mv:

git mv -f OldFileNameCase newfilenamecase
  • 9
    this gives me 'source directory is empty' while it is not – WiseStrawberry Jul 19 '14 at 13:10
  • 2
    fatal: Will not add file alias 'File.svg' ('file.svg' already exists in index) [had that in webstorm, but worked fine in CLI) – Damon Mar 24 '16 at 15:03
  • 3
    Using MacOS here (case-insensitive FS) and -f worked! Thanks for the tip – caesarsol Dec 15 '16 at 18:08
  • 32
    In recent versions, you no longer need the -f flag. – Joshua Pinter Apr 22 '17 at 4:43
  • 5
    Don't forget to give the full file path. Obvious, I know, but got me for a while – rickrizzo Aug 15 '17 at 16:03

Git has a configuration setting that tells it whether to be case sensitive or insensitive: core.ignorecase. To tell Git to be case-senstive, simply set this setting to false:

git config core.ignorecase false


From the git config documentation:


If true, this option enables various workarounds to enable git to work better on filesystems that are not case sensitive, like FAT. For example, if a directory listing finds makefile when git expects Makefile, git will assume it is really the same file, and continue to remember it as Makefile.

The default is false, except git-clone(1) or git-init(1) will probe and set core.ignorecase true if appropriate when the repository is created.

Case-insensitive file-systems

The two most popular operating systems that have case-insensitive file systems that I know of are

  • Windows
  • OS X
  • 8
    On a side note, I don't think that Mac OS X itself is case-insensitive. Instead, it's the filesystem that determines case-sensitivity. When formatting a HFS+ partition, users can choose whether to make it case-sensitive or insensitive. Case case-insensitive is the default. – spaaarky21 Dec 16 '14 at 19:02
  • 176
    It seems very worth noting in this answer that setting this option to false on a case-insensitive file system is a bad idea. This isn't necessarily obvious. For example, I just tried this on my Mac, thinking it would fix my problems, then renamed a file from productPageCtrl.js to ProductPageCtrl.js. git status saw a new file called ProductPageCtrl.js but didn't think that productPageCtrl.js had been deleted. When I added the new files, committed, and pushed to GitHub, the GitHub repo now contained both files even though my (supposedly up to date) local repo had only one. – Mark Amery Feb 9 '15 at 10:25
  • 4
    @MarkAmery That sounds a lot like a bug in your Git client. Did you file a report? – Domi Feb 13 '15 at 11:49
  • 14
    @Domi this is not a bug, this is expected behavior. It is in fact a bad idea to set this to false on an insensitive filesystem because this is what happens. The reason why git didn't saw the lower-case file been deleted is that the filesystem doesn't report it as deleted as it does ignore the case while git does not with this option set to false. Its not that the filenames don't have lower vs upper case on ntfs or fat its just that filename lookup is ignoring the case. – ohcibi Jun 2 '16 at 17:40
  • 12
    @Domi git is smart enough. Thats why you should not set this to false on a case insensitive file system. Use git mv to move the file and see how git manages it. If you move the file without git, there is nothing git can do as the filesystem isn't telling the truth to git. This is an issue of ntfs/fat/hfs and thelike and not git/linux. – ohcibi Jun 3 '16 at 5:06

Using SourceTree I was able to do this all from the UI

  1. Rename FILE.ext to whatever.ext
  2. Stage that file
  3. Now rename whatever.ext to file.ext
  4. Stage that file again

It's a bit tedious, but if you only need to do it to a few files it's pretty quick

  • 5
    The same with git bash – Alex78191 Jun 3 '17 at 17:01
  • 3
    "Stage that file" is the important part - none of the other answers above worked for me. It actually worked with the plain old Windows command prompt. – Vlad Sabev Dec 21 '17 at 16:43
  • I didn't realize this worked through the staging area. But in my case, I wanted to modify the folder names as well as some files within those folders. So I first renamed all folders to temporary names. Committed the new names (all files within) and the "deleted" files. Git flagged them all as "renamed". Then renamed all those folders back to their new case versions and committed again. Finally, merged those 2 commits. But based on what you wrote, I could have done the whole thing through the sating area directly, without creating 2 commits + merge. – ThermoX Oct 12 '18 at 16:08
  • 1
    Works also with gitkraken on folder name. – Philippe Matray Oct 29 '18 at 9:55

This is what I did on OS X:

git mv File file.tmp
git mv file.tmp file

Two steps because otherwise I got a “file exists” error. Perhaps it can be done in one step by adding --cached or such.

  • 16
    as the top answer suggests, -f (force) is the flag you are looking for – rperryng Jul 9 '15 at 22:08
  • 2
    @rperryng - no, the -f flag doesn't help in case the underlying FS is case-insensitive. However, two-step solution worked for me – HEKTO Sep 28 '16 at 18:34
  • Using a case-insensitive FS (on Mac) and -f worked! Thanks for the tip – caesarsol Dec 15 '16 at 18:07
  • doesn't work on linux – Sungguk Lim Dec 20 '16 at 1:37
  • 1
    This should be the accepted answer for Windows. The only one that worked for me! – vezenkov May 5 '17 at 9:01

Under OSX, to avoid this issue and avoid other problems with developing on a case-insensitive filesystem, you can use Disk Utility to create a case sensitive virtual drive / disk image.

Run disk utility, create new disk image, and use the following settings (or change as you like, but keep it case sensitive):

Mac Disk Utility Screenshot

Make sure to tell git it is now on a case sensitive FS:

git config core.ignorecase false
  • 69
    Sort of the nuclear option, isn't it? – Tim Keating Jan 15 '15 at 17:59
  • 14
    Nah, nuclear is running a fully case-sensitive boot drive on OSX. You'll have to live without poorly written (ahem, Adobe) apps, or run those in their own case-stupid VM, but it's worth it if you code primarily for *nix systems. – Mike Marcacci Aug 6 '15 at 1:33
  • 1
    This is the only option that properly works. I've tried the rest and you end up in a pickle one way or another. Solve the problem properly by doing this. – John Hunt Jun 3 '16 at 9:12
  • 2
    Note that Disk Utility has a bug OS X 10.11 -- It won't create case sensitive images. You need to use the command line tool hdiutil. apple.stackexchange.com/questions/217915/… – dellsala Jan 18 '17 at 20:51
  • 6
    With APFS in High Sierra this is even easier. Click the icon of a drive with a plus and add a case-sensitive volume with no limits on size. It just shares space with the main volume and mounts at /Volumes/volume-name. – Michael Fox Aug 30 '17 at 13:02

It can sometimes be useful to temporarily change Git's case sensitivity. Two possible methods:-

Method 1 (very temporary):

git -c core.ignorecase=true checkout mybranch to turn off case-sensitivity for a single checkout command. Or more generally: git -c core.ignorecase= <<true or false>> <<command>>. (Credit to VonC for suggesting this in the comments.)

Method 2 (semi-permanent):

To change the setting for longer (e.g. if multiple commands need to be run before changing it back):

  1. git config core.ignorecase (this returns the current setting, e.g. false).
  2. git config core.ignorecase <<true or false>> - set the desired new setting.
  3. ...Run multiple other commands...
  4. git config core.ignorecase <<false or true>> - set config value back to its previous setting.
  • 1
    Why not directly git -c core.ignorecase=<true or false> checkout <<branch>>? Nothing to reset after. – VonC Jul 10 '18 at 11:28
  • Very good point - have updated the answer to include this. – Steve Chambers Jul 10 '18 at 13:08
  • I had a weird experience of the proposed core.ignorecase working when changing from lowercase to uppercase, but not for uppercase to lowercase. seems the only reliable solution is to stop using an OS which fails to recognise filename case. – aspiringGuru Sep 30 '18 at 2:56
  • Is there a reason why it should be a temporary change? Would that cause any problem if I just leave the settings changed to case sensitive? – cytsunny Jan 24 at 9:39
  • This may depend on a few factors, in particular whether the target file system is case sensitive - see en.wikipedia.org/wiki/Case_sensitivity#In_filesystems. The temporary change may be needed if the deployment file system has different case sensitivity to the file system used for development. Also in my case I work in a team where everyone is expected to have the same Git settings (i.e. case sensitive) so if I turn it off it needs to be temporary. – Steve Chambers Jan 24 at 9:49

1) rename file Name.jpg to name1.jpg

2) commit removed file Name.jpg

3) rename file name1.jpg to name.jpg

4) ammend added file name.jpg to previous commit

git add
git commit --amend
  • 1
    I am getting this fatal: bad source, source=name1.jpg, destination=name.jpg at step 3. Do you have suggestion? Thx – Anthony Kong Mar 30 '17 at 0:48
  • 1
    You can not do a commit, just git add. – Alex78191 Jun 3 '17 at 17:00
  • Looks very hacky, isn't it? Or monkey-patching. – JeromeJ Oct 2 '18 at 14:53

I tried the following solutions from the other answers and they didn't work:

If your repository is hosted remotely (GitHub, GitLab, BitBucket), you can rename the file on origin (GitHub.com) and force the file rename in a top-down manner.

The instructions below pertain to GitHub, however the general idea behind them should apply to any remote repository-hosting platform. Keep in mind the type of file you're attempting to rename matters, that is, whether it's a file type that GitHub deems as editable (code, text, etc) or uneditable (image, binary, etc) within the browser.

  1. Visit GitHub.com
  2. Navigate to your repository on GitHub.com and select the branch you're working in
  3. Using the site's file navigation tool, navigate to the file you intend to rename
  4. Does GitHub allow you to edit the file within the browser?
    • a.) Editable
      1. Click the "Edit this file" icon (it looks like a pencil)
      2. Change the filename in the filename text input
    • b.) Uneditable
      1. Open the "Download" button in a new tab and save the file to your computer
      2. Rename the downloaded file
      3. In the previous tab on GitHub.com, click the "Delete this file" icon (it looks like a trashcan)
      4. Ensure the "Commit directly to the branchname branch" radio button is selected and click the "Commit changes" button
      5. Within the same directory on GitHub.com, click the "Upload files" button
      6. Upload the renamed file from your computer
  6. Locally, checkout/fetch/pull the branch
  7. Done
  • I renamed directly on BitBucket and it worked. Thanks. – rsc Dec 24 '17 at 0:21
  • Good to know. This technique should theoretically work on any repository hosting platform but I'd be interested to know if there are any that it would not work with. – gmeben Jan 2 '18 at 19:11
  • Doesn't work for files that can't be edited in the browser, like images or PDF; there is no edit option, obviously. – Abhijit Sarkar Dec 26 '18 at 20:16
  • @AbhijitSarkar Good point. I updated my answer for those cases. I tested and verified these instructions work. – gmeben Jan 11 at 20:36

Mac OSX High Sierra 10.13 fixes this somewhat. Just make a virtual APFS partition for your git projects, by default it has no size limit and takes no space.

  1. In Disk Utility, click the + button while the Container disk is selected
  2. Select APFS (Case-Sensitive) under format
  3. Name it Sensitive
  4. Profit
  5. Optional: Make a folder in Sensitive called git and ln -s /Volumes/Sensitive/git /Users/johndoe/git

Your drive will be in /Volumes/Sensitive/

enter image description here

How do I commit case-sensitive only filename changes in Git?

  • I love this suggestion, it elegantly and painlessly solves the problem without resort to ugly workarounds. Thanks! – Phil Gleghorn Sep 24 '18 at 23:42

I used those following steps:

git rm -r --cached .
git add --all .
git commit -a -m "Versioning untracked files"
git push origin master

For me is a simple solution


I've faced this issue several times on MacOS. Git is case sensitive but Mac is only case preserving.

Someone commit a file: Foobar.java and after a few days decides to rename it to FooBar.java. When you pull the latest code it fails with The following untracked working tree files would be overwritten by checkout...

The only reliable way that I've seen that fixes this is:

  1. git rm Foobar.java
  2. Commit it with a message that you cannot miss git commit -m 'TEMP COMMIT!!'
  3. Pull
  4. This will pop up a conflict forcing you to merge the conflict - because your change deleted it, but the other change renamed (hence the problem) it
    1. Accept your change which is the 'deletion'
    2. git rebase --continue
  5. Now drop your workaround git rebase -i HEAD~2 and drop the TEMP COMMIT!!
  6. Confirm that the file is now called FooBar.java

When you've done a lot of file renaming and some of it are just a change of casing, it's hard to remember which is which. manually "git moving" the file can be quite some work. So what I would do during my filename change tasks are:

  1. remove all non-git files and folder to a different folder/repository.
  2. commit current empty git folder (this will show as all files deleted.)
  3. add all the files back into the original git folder/repository.
  4. commit current non-empty git folder.

This will fix all the case issues without trying to figure out which files or folders you renamed.

  • Why not git commmit --amend in In paragraph 4? Otherwise, there will be an extra commit with the removal of all files. Or you can use git rebase -i with squash. – Alex78191 Jun 3 '17 at 17:06

Similar to @Sijmen's answer, this is what worked for me on OSX when renaming a directory (inspired by this answer from another post):

git mv CSS CSS2
git mv CSS2 css

Simply doing git mv CSS css gave the invalid argument error: fatal: renaming '/static/CSS' failed: Invalid argument perhaps because OSX's file system is case insensitive

p.s BTW if you are using Django, collectstatic also wouldn't recognize the case difference and you'd have to do the above, manually, in the static root directory as well


If nothing worked use git rm filename to delete file from disk and add it back.

Your Answer

