I have a git repository in a remote machine. I mounted it on my local machine. But whenever I run any git command in that repo, it hangs forever. Even git status does not work. Why this happens? Is this because git versions on both machines are different?
EDIT: No, it is not because of different git versions. Git simply doesn't work on mounted directories. If someone know why, please help.
EDIT: I'm using Ubuntu16.04 in WSL2 in Windows 10. I mounted a cifs filesystem by adding new entry in /etc/fstab file and running sudo mount -a. Then I cd to that directory, then git lfs cloned a repository. Repository is quite huge, so I used -I option to include a single file. Then I tried common git commands like git status etc. It froze for a lot of time. Then I interrupted it. Logged on to the remote machine, did git status. There it ran. Then I logged back to local and tried, it was working fine for some time. Then again when I tried to git add files, it froze. It could be an issue with git-lfs also, not sure.
When you run
git statusor any other command that refreshes the index, Git checks the cached stat information that's already in the index to see if the file has been modified. If the information doesn't match, then the file has been modified, and Git re-reads it. If the file is tracked by Git LFS, it gets cleaned through Git LFS, which also must hash it and store it.Now, part of that information includes things like the device and inode number, which are different when you're using a remote file system versus a local file system. Thus, when you're doing
git statuson the remote file system, you're re-reading every file in the working tree to see if it's been updated. The operation is not hanging, it's just really slow because of that.This also happens when people use the same repository both inside and outside a Docker container, or in a variety of other situations where the repository is accessed via two different file systems.
In general, you should avoid trying to share a repository with a working tree across machines because of that problem. However, there are some Git options which can help, and you should try them in this order.
First, you can try setting
core.untrackedCachetotrue. You must first check that that works properly by runninggit update-index --test-untracked-cacheon both the local and remote versions. That can prevent needing to re-read information for untracked files.Second, you can try setting
core.trustctimetofalse. That will ignore setting the ctime, which can help if both sides don't accurately reflect that.Finally, you can set
core.checkstattominimal. This removes the device and inode number from the file, but it also makes it much more likely that Git will be unable to detect some changes made to the repository. Thus, this should be a last resort.