Git – File Operations – Case Sensitivity

Background

If you use git from the command line as I do, you will likely run into git file command requests that does not stick.

For instance, you issue “git add <filename>“.

And, issue “git commit” or “git status” and notice that the file you added is not tagged for local commit.

If your file name is correct, you may have experience the issue highlighted in this post.

 

Troubleshoot

Outline

  1. OS Commands
    • File List
      • Microsoft Windows
        • dir
      • Linux
        • ls
  2. Git
    • Git Command
      • git status
    • Git Configuration
      • File
        • File – .git\config
          • [core] / ignorecase = true
      • Git Command
        • git config
          • local
          • global

OS Commands

File List

OS – Microsoft Windows

dir

On a machine running Microsoft Windows, please try using the “dir” command.

OS – Linux

ls

On a machine running Linux, please try using the “ls” command.

Summary

Irrespective of the OS that you using, your hope is to compare the file names.

The name should be same as the one you use targeted within the git command; making sure to match on case, as well.

 

Git

Git Command

Git Status

Please try using git status to get a file level read of your repository.

My go to command git status option is the “-u” option.

In essence, I issue “git status -u“.

 

Git Configuration

File

File – .git\config

[core] / ignorecase = true
Sample – Linux
 

cat .git/config

Sample – Windows
 

type .git\config

Output – Image

Output – Text

[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        ignorecase = true

 

Explanation
  1. ignorecase
    • Setting:- ignorecase = true
      • Ignore case is set to true
      • Which seems to imply that case sensitivity is set to be immaterial when it comes to file names

 

Git Command

git config

local

core.ignorecase
get
 

git config --local core.ignorecase

Output – Image

Output – Text

>git config --local core.ignorecase
true

 

Explanation
  1. ignorecase
    • Setting:- ignorecase = true

global

core.ignorecase
get
 

git config --global core.ignorecase

Output – Image

Output – Text

git config --global core.ignorecase

 

Explanation
  1. ignorecase
    • Setting:- ignorecase = <blank>
    • In our case, the ignorecase option was not set globally

Additional Reading

  1. Scott Hanselman
    • Git is case-sensitive and your filesystem may not be – Weird folder merging on Windows
      Link
  2. syntevo
    • SMARTGIT
      • Be sure that core.ignoreCase matches your OS!
        Link

Scott Hanselman

Git is case-sensitive and your filesystem may not be – Weird folder merging on Windows

Link

Folders with mismatched names Worked on MS Windows and Mac OS.

But, failed on Linux.

Premise is that on MS Windows and Mac OS, we have a single folder.

On Linux, two or more different folders; for each case-sensitive folder name.

Syntevo GmbH

SmartGit

Be sure that core.ignoreCase matches your OS!

Link

Marc @ Ainring, Germany based Syntevo GmbH was just as circumspect.

When copying repositories back and forth between Windows and Linux/MacOS, you may end up either with core.ignoreCase=false on Windows or core.ignoreCase=true on Linux. Both configurations will usually cause troubles and are not supported by Git.To avoid this, you may unset the core.ignoreCase configuration in your repository root:

$ git config --unset core.ignoreCase

As Git’s internal default is false, there is nothing more to do on Linux/MacOS. On Windows, you have to add core.ignoreCase=true as global default:

$ git config --global core.ignoreCase true

Summary

For the sake of this particular post, I intentionally circumvented an attempt to add a new file to Git, knowing that it will not be added; as I mangled via casing the file name. 

If you google on the error, and someone says check on the core.ignorecase setting, please do check on it.

But, please carefully consider prior to amending globally or locally to a targeted repository.

One thought on “Git – File Operations – Case Sensitivity

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s