Dragan Nikolic
Dragan Nikolic

Reputation: 1766

How to get Linux VM (on Windows host) to access the git working files on a shared directory

I have a Windows PC and on the same PC I have a Lubuntu VM inside the VMWare player.

I share my Windows folders so I can see them from the Lubunutu VM.

My problem is when I clone a Git repo on Windows (using Tortoise Git) and then try to access it from Lubuntu (using Git from command line) all files appear modified although I have not changed them.

I know that reason for this is that Windows and Linux handle the new lines differently.

My question is how can I configure my Git installations on Windows and on Lubuntu so I do not have this problem?

Update:

As suggested (by Craig Estey) this does not seem to be CRLF problem. I tried cloning a repo in my Linux VM on the shared directory and got following error:

fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.`

I have no problem cloning the same repo on the VM's local drive.

Any idea what could be the reason?

Note: The main reason I want to do this is to keep my VM's drive size small and use shared drive as much as possible. My VM's local drive is on SSD drive and shared drive is on much larger HDD.

Upvotes: 0

Views: 2593

Answers (1)

Yue Lin Ho
Yue Lin Ho

Reputation: 3111

Suppose you put a repository into a Windows Shared folder.

And mount(Mount shared folder on Ubuntu) that shared folder on Ubuntu, so you can clone that repository. (Talking about you can not clone, it must be another problem. I tested it, good for me.)

When you cd to that repository in that mount, you see all files are modified on Ubuntu, then it should be the EOL problem.

On Windows the autocrlf is true by default(assume you are using Git for Windows).

When you clone a repository on Windows, the files will be checkout with CRLF EOL.

But, On Ubuntu the autocrlf is false by default. Using git in that repository which is mount on Ubuntu, git expects the EOL is LF. But, the EOL is still CRLF. That's why git treats all file as modified on Ubuntu.

To fix this problem, make sure both OS to use the same autocrlf value, or using .gitattributes to control the EOL.

For example, using false value:

On windows,

  1. Delete all files in working tree of that repository.

    (Note: if you have local changes, commit them first.)

  2. Run git config core.autocrlf false for that repository only. Or

    • Right click in that repository, click TortoiseGit -> Setting
    • In Settings dialog, go Git node, select local and un-check the AutoCrlf
    • Apply the change
  3. Perform git reset hard to get all files back with correct EOLs.

    • Open TortoiseGit Log Message dialog
    • Right click on current branch and perform Reset "<current branch name>" to this
    • Choose "Hard" option

On Ubuntu, you should not see all files modified.

For using .gitattributes:

* -crlf

Upvotes: 1

Related Questions