Setting up git running under WSL
I recently ran into a problem running git from inside a WSL (Windows Subsystem Linux) command prompt to manage a git repository stored in a folder outside the WSL file system. In my case that location was C:\projects but I believe the problem would exist for any location outside the WSL directory.
The error message looked like this when I tried to
error: chmod on /mnt/c/projects/<repo>/.git/config.lock failed: Operation not permitted
fatal: could not set 'core.filemode' to 'false'
I could overcome the issue by using
sudo but other git operations would fail when I tried to use the local repository. The fix (detailed here on askubuntu) was to remount the C:\ drive with the metadata flag enabled to allow
chown commands to work on the C:\ partition.
sudo umount /mnt/c
sudo mount -t drvfs C: /mnt/c -o metadata
More details are in the Microsoft release notes for setting default file permissions in the WSL partition and help configuring other mount options.
An outcome of that change was that I was seeing file permissions changes from
755 when I edited a file in Visual Studio or any Windows application. To fix this, make sure that the
core.filemode is set to false inside each git repository where you see the permissions being changed -
git config core.filemode false.