This started appearing with the release of the git 2.35.2 security update which fixes vulnerabilities described here. credits @Juan-Kabbali
Here are 4 possible solutions:
- trust git directory (do it if you know the directory contents are safe)
git config --global --add safe.directory /home/repon
This adds to ~/.gitconfig the safe group as shown in this example
[safe]
directory = /home/repon
- run the command as the correct user, for example:
sudo -u ubuntu -- git status
Note: This requires user www-data to have permission to execute the git command as user ubuntu (assuming ubuntu is the repository owner). For this to work, you will need to add a new file inside /etc/sudoers.d/ with the following contents:
www-data ALL=(ubuntu) NOPASSWD: /usr/bin/git
This may have security implications so refer to your security person first.
- change git repository owner to
www-data
sudo chown -R www-data:www-data /home/repon
- downgrade git as a temporary solution. For example in Ubuntu:
apt install git-man=1:2.17.0-1ubuntu1 git=1:2.17.0-1ubuntu1
Note: At least on Windows, it appears that all git repositories on ejectable drives are considered unsafe and changing ownership does not seem to work.