For anybody who encounters this with Windows share or shared drive and the command it offers, e.g.
git config --global --add safe.directory 'X:/R/repo'
does not help, add this to global git config
[safe] directory = *