294

I'm developing a project on OS X Lion that is under Git version control. I had these lowercase directories and then later capitalized them (e.g. emailaddresses => EmailAddresses), but Git doesn't seem to recognize the change. It still thinks the directories are lowercase when I run git ls-files and other commands.

Is this harmless, or should I do something else to get Git to pick up on this change?

Paul R
  • 208,748
  • 37
  • 389
  • 560
dan
  • 43,914
  • 47
  • 153
  • 254
  • 2
    possible duplicate of [Git: Changing capitalization of filenames](http://stackoverflow.com/questions/10523849/git-changing-capitalization-of-filenames) – KyleMit Aug 20 '15 at 12:22

9 Answers9

574

You can tell git to take account of the case by running

git config core.ignorecase false

Taran
  • 12,822
  • 3
  • 43
  • 47
  • 10
    Really great answer if you have already changed the file names without using git mv --force or some other CL script. Thank you! – MeanMatt Dec 15 '16 at 01:48
  • 13
    This is the superior answer as I didn't particularly feel like git mv'ing 200 renamed files manually! – Adam Reis Aug 22 '17 at 21:15
  • 10
    for some reason it duplicated all the files, now I have both the original versions and the ones with capitalization changed... – Salatiel Apr 01 '20 at 01:49
  • 3
    @Salatiel I guess it duplicates them when you're already tracking the file. – Iggy Apr 14 '20 at 22:31
  • I needed to remove the previous files in my local repo if I change the names (literally just tu capitalize the files) in the remote one (like GitHub). – dawn Feb 08 '21 at 04:59
  • 2
    bear in mind using this command will give duplicated files/folders when pushing files/folders with same name but different capitalization in case insensitive OS (Windows) – rick Jan 26 '22 at 05:45
  • 1
    I found this left me with no noticed working directory changes (despite names not matching what's on git). Deleting, staging, undeleting the files, and staging again made them get noticed after I did this. – Phoenix Sep 16 '22 at 15:41
  • 1
    This answer causes problems on case-insensitive filesystems and is explicitly not recommended: https://stackoverflow.com/a/52369235/8869677 – Phoenix Jun 01 '23 at 15:29
316

You're probably using case insensitive (but case preserving) HFS+. I usually work round this like so:

$ git mv somename tmpname
$ git mv tmpname SomeName
Paul R
  • 208,748
  • 37
  • 389
  • 560
  • 3
    Had the same problem with the Github for Windows tool. Again the above solution works around the issue nicely: rename to a temporary file in Windows Exploer, then - after committing - rename to the final name with the correct case. – Jason Nov 25 '12 at 18:30
  • 14
    Or do it in one command: git mv --force somename SomeName (from http://stackoverflow.com/a/16071375/217866) – jackocnr Jul 24 '13 at 10:53
  • 2
    For the changes to be reflected in the remote repo you also need to `git push origin master`. If git refuses to update the remote you may need to add a dummy file (e.g. `touch stam`) and do the push. Followed by a subsequent delete of stam and push again. – Rahav Aug 06 '18 at 23:17
  • 1
    @SagunKho: try `git mv --force somename SomeName` instead. – Paul R Oct 02 '18 at 11:53
  • 2
    One thing to note is that you need to be in the folder where the file is for this to work. It was not obvious for me at first and I kept getting >>> bad source, source=somename, destination=tmpname <<< because I was trying to run the command from the root of the repo. – Parth Dec 26 '19 at 01:43
  • 1
    Does not work even with `--force` because Git says the file doesn't exist. – Taimoor Ahmad Oct 17 '20 at 15:37
42

How to git mv on Mac Case-Sensitively

This is happening because Mac OS X implements case preserving and case insensitivity features that are intended to help you.

Although the double rename suggestions in the other answer will work, I recommend the use of '--force' for a best practice result:

$ git mv --force somename SomeName


Note: if you try without the force option, git will barf on you like this:

$ git mv somename SomeName
$ fatal: destination exists, source=somename, destination=SomeName

In the above example, the git command fails and no files are changed in the filesystem or in git's index.

David Manpearl
  • 12,362
  • 8
  • 55
  • 72
  • Upon the first command, I get `fatal: not under version control`. – 2540625 Sep 07 '15 at 20:54
  • That fatal error means you do not have a GIT repository at that location. `git` commands only work in directories with GIT repositories. – David Manpearl Sep 08 '15 at 18:43
  • But I was in a subdirectory of my Git repo… In the end, I solved it via [Taran's answer](http://stackoverflow.com/questions/6899582/i-change-the-capitalization-of-a-directory-and-git-doesnt-seem-to-pick-up-on-it/31393409#31393409), BTW. Thanks. – 2540625 Sep 09 '15 at 00:09
25

Try to change git config option core.ignorecase to false in your .gitconfig file.

Poomalairaj
  • 4,888
  • 3
  • 23
  • 27
21

The following steps helped me resolve the issue:

  1. Rename the folder to temp:

    mv Folder temp                  // It will rename your Folder to temp
    
  2. Stage and commit:

    git add .
    git commit -m "Temp"
    
  3. Rename temp folder to your choice:

    mv temp folder        // It will rename temp folder to the name of your choice(folder)
    git add .
    git commit -m "Folder Fixed"
    

Done - You can now push.

RobC
  • 22,977
  • 20
  • 73
  • 80
Renil Babu
  • 2,118
  • 1
  • 20
  • 29
7

The reason for this is that LINUX-based OS or macOS ignore case sensitive for file/folder name. We need to resolve this problem by the below steps

For Exp, you want to change folder name from Base to base
1. mv Base base2
2. git add . && git commit -m "Fix folder name problem (wip)"
3. mv base2 base
4. git add . && git commit -m "Fixed folder name problem"
giapnh
  • 2,950
  • 24
  • 20
4

If you do git mv AAA aaa or git mv -f AAA aaa, it will not be work and you will have error fatal: renaming 'AAA' failed: Invalid argument.

Because AAA and aaa are ONE SAME folder/file on case-insensitive file systems, move AAA to aaa means move AAA as aaa/AAA.

So you should do

git mv AAA aaa.1
git mv aaa.1 aaa

I hope it will be helpful for you.

Gapur Kassym
  • 1,131
  • 12
  • 10
1

None of these actually helped me, I still was having git tell me to stash my changes, because my situation was that my local folder was capitalised but the remote not, and my branch was behind and I could no longer pull because of file capitalization differences in the folder structure.

The only way I could fix this was deleting my local branch and checking out the remote.

Derrops
  • 7,651
  • 5
  • 30
  • 60
-2

You can also do this manually without using GIT commands. Inside the .git folder, simply delete the folder with the name you want i.e SomeName . And then rename the folder somename to SomeName. More details at : How to fix folder name set to uppercase and git convert to lowercase

Taha
  • 59
  • 7