advait
advait

Reputation: 6525

Git (MacOS) case sensitive overwrite issues

I'm working on a team with mixed Linux/MacOS developers. MacOS is case insensitive while Linux is case sensitive. I've got the following issue:

My (MacOS) machine:

$ git checkout master
$ echo hi > MyModule.js
$ git commit -a -m 'Create MyModule.js'
$ git push origin master
$ git checkout -b other-work
... (do work)

Coworker's (Linux) machine

$ git checkout master
$ git pull
$ git mv MyModule.js myModule.js
$ git commit -m 'Rename MyModule.js to myModule.js'
$ git push

My (MacOS) machine

# Currently on branch other-work
$ git fetch
$ git checkout origin/master
error: The following untracked working tree files would be overwritten by checkout:
    MyModule.js
# In order to resolve the issue, I have to resort to hackery:
$ rm MyModule.js
$ git checkout origin/master
$ git checkout -- myModule.js   # Restore the rm'd file

I'd really like to avoid all of this hackery. I want my MacOS git to be aware of case changes in file names so that so that I can switch between branches freely. I've tried setting the ignorecase config value to both true and false but this does not help.

Upvotes: 12

Views: 8421

Answers (3)

vhs
vhs

Reputation: 10089

As suggested, macOS uses a case-insensitive file system. This is only for the default volume, however. To overcome this issue create another volume on macOS machines which is case-sensitive and store shared code there. Alternatively, standardize within your organization so case-sensitive files are no longer a concern.

To quickly get a volume created on your Mac so you're not blocked while waiting for a standards discussion internally, access Disk Utility and create a new case-sensitive volume like:

Linux Share

That will at least get you moving so your environment will behave like that of your co-workers and the error you were seeing should no longer occur.

Upvotes: 11

advait
advait

Reputation: 6525

When switching branches a git checkout --force does what I want but it's a bit dangerous.

From the git docs:

   -f, --force
       When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes.

       When checking out paths from the index, do not fail upon unmerged entries; instead, unmerged entries are ignored.

Upvotes: 1

Stuart Miller
Stuart Miller

Reputation: 657

They was I get round this is to have a partition formatted as case sensitive.

This is then where all my dev sites are served from.

Upvotes: 2

Related Questions