Home > Mobile >  Git error when trying to change the remote repo within WSL
Git error when trying to change the remote repo within WSL

Time:09-19

image of command line

As mentioned above, I am presented with this error when trying to run

git remote set-url origin x

This error only occurs within WSL and works fine in cmd in windows. Any ideas?

CodePudding user response:

Your linux file system does not have write privileges. The following will assign write privilege to the entire contents of your .git folder:

# Assuming you are in the collegework folder
chmod -R  w .git

Then try the command again.

CodePudding user response:

This is a WSL bug. In general, when Git writes a new configuration file, it will set the permissions accordingly on the lock file so that when it renames the lock file into place, it has the correct permissions.

However, in this case, WSL says that the chmod system call, which performs this, doesn't work on this file. That's because unlike Linux, which actually just ignores the permissions change on file systems which don't support it, WSL simply refuses to perform the operation and returns an error code when operating on a Windows path.

There's unfortunately no way around this when using a Linux Git on a Windows path, so you need to modify the .git/config file by hand to update the remote URL. Linux distributions are not going to modify their Git implementations to change this since the behaviour is due to WSL, which they don't ship, and this works just fine on Linux itself.

  • Related