0

I want to sync the same repositories between Linux/Mac/Windows so I need the Git internals (basically what's inside .git) be case insensitive compatible (so I don't want duplicate files there where only the case differs).

My main work machine is on Linux from where I want to sync these Git repositories to Mac/Windows.

I noticed that the directory .git/logs/refs/remotes/origin/ on Linux sometimes contains the same branch name with the original name (like TICKET-123-fix-this-thing) but also lowercased (ticket-123-fix-this-thing).

Is there a way to avoid this behavior (and possibly others I haven't yet noticed) so I can use this same repository on Mac and Windows? So basically, what I need to do to make the .git directory fully compatible (with regards to case) between Linux/Mac/Windows.

Thanks!

Andrei
  • 3
  • 1
Marian
  • 15
  • 2
  • git config --global core.ignorecase true? might help maybe? – D3PSI Aug 01 '21 at 13:01
  • @D3PSI Will this really help? From what I read it refers to how Git will treat the files in the repository (like considering them the same file if multiple are present where only case differs), so doesn't seem to refer to Git internals (.git directory). – Marian Aug 01 '21 at 13:09
  • You could also just manually rename (or write some script to do it for you) all the files inside the `.git/refs/heads/` directory (where branches are stored) to lowercase – D3PSI Aug 01 '21 at 13:14
  • @D3PSI The problem is I don't really know what Git does with those files and how they came to be this way so I wouldn't want to mess with them. Just thought there was a simpler way to enable a compatibility mode like the one you mentioned but for its internals in the .git directory. – Marian Aug 01 '21 at 13:18

1 Answers1

3

You cannot do this. The core.ignorecase setting informs Git how your system works. It does not change how your system works. Overriding the setting simply mis-informs Git, which will subsequently misbehave (in predictable ways which are occasionally useful, but won't help you here).

What you can do, on a macOS system, is make yourself a case-sensitive file system. Here, your Git will behave the same way it does on a standard Linux file system. See my answer here.

You can, on a Linux system, make yourself a case-insensitive file system; see this ServerFault question.

torek
  • 448,244
  • 59
  • 642
  • 775
  • I'm thinking the same repo should be portable though - these files are only a few among thousands and they are empty. Maybe you or someone else could shed some light on what Git does with these files and how they came to exist in two versions (lowercase and original). – Marian Aug 01 '21 at 14:42
  • Git branch names *are case sensitive*. The Git implementation on macOS and Windows is defective in that it sometimes fails to distinguish these different branches (due to the default file system behavior). The result is bad behavior on these OSes. This is very slowly being fixed; some future version of Git will distinguish between branch FOO and branch Foo, and you will be able to have both branches even on a default Windows or macOS setup. – torek Aug 01 '21 at 14:46
  • These things come into existence when someone on Windows or macOS tries to use branch FOO or branch foo, but spells it Foo instead. This *works* (sort of) for them and they mess things up for you if you're on Linux. Or, they come into existence when someone on Linux deliberately makes branches that differ only in case. This *works* for them, and they mess things up for you if you're *not* on Linux. – torek Aug 01 '21 at 14:48
  • Sometimes, Git stores branch names in a "flat file" pseudo-database named `.git/packed-refs`. When it does so, the branch names *are always case sensitive:* things work the same on Linux and other systems, and branches FOO and Foo and foo are three different branches. – torek Aug 01 '21 at 14:49
  • But as long as I am careful to avoid using conflicting filenames and conflicting branchnames etc. (which I will do) will Git also ensure the repositories are portable between Linux and Mac? – Marian Aug 01 '21 at 14:58
  • Yes. Note that Git considers *files* `foo` and `FOO` to be different names too, and is capable of storing that just fine in the *repository*. It's the *checkout*, into a case-insensitive file system, that creates problems. See my macOS answer for additional information. Note also that the files inside a `.git` directory *must* be created and controlled by a Git running *on* that system; allowing other programs to do so, or letting this happen on a shared drive, is asking for problems. – torek Aug 01 '21 at 15:01