DEV Community

Pacharapol Withayasakpunt
Pacharapol Withayasakpunt

Posted on

Git on Windows (vs *nix, via WSL2) - does "file mode" matter?

So, I happened to use Git on a repo cloned to Windows filesystem, but with WSL2 shell, and sent git commands via WSL2 zsh.

That is, in settings.json.

{
  "terminal.integrated.shell.windows": "C:\\windows\\System32\\wsl.exe"
}
Enter fullscreen mode Exit fullscreen mode

Git is installed on both Windows and WSL2.

It appears that file mode when created with Git on Windows is 644, but on WSL2 Ubuntu, it is 755. I found this out when switching branches with VSCode (outside Remote WSL2 plugin).

Quick fixes

  • Current repos
sed 's/filemode = true/filemode = false/' .git/config
Enter fullscreen mode Exit fullscreen mode
  • Globally. Run this on both WSL2 shell and PowerShell.
git config --global core.fileMode false
Enter fullscreen mode Exit fullscreen mode

Additional notes

I don't know how you keep up with Git on Windows. So many choices to be made on set up. I did none of these on macOS or Linux.

Top comments (1)

Collapse
 
baddate profile image
SMJ

maybe you can refer to this.

core.fileMode

Tells Git if the executable bit of files in the working tree is to be honored.

Some filesystems lose the executable bit when a file that is marked as executable is checked out, or checks out a non-executable file with executable bit on. git-clone(1) or git-init(1) probe the filesystem to see if it handles the executable bit correctly and this variable is automatically set as necessary.

A repository, however, may be on a filesystem that handles the filemode correctly, and this variable is set to true when created, but later may be made accessible from another environment that loses the filemode (e.g. exporting ext4 via CIFS mount, visiting a Cygwin created repository with Git for Windows or Eclipse). In such a case it may be necessary to set this variable to false. See git-update-index(1).

The default is true (when core.filemode is not specified in the config file).

====

from git-config