Git: Unsafe repository is owned by someone else (Windows)

After updating git the following message appeared during opening the repository with SourceTree:

I tried out two different possibilities to solve this problem. First, I added the recommended command from the error message

git config --global --add safe.directory <repo-path>

This solution works fine but has the big impact that changing the repository path afterwards would lead to the same error again. So I removed the entry from

C:\Users\<username>\.gitconfig

and I found out that a better soluation would be to adapt the security settings for the repository in Windows by performing the following steps:

  • Open Windows “Explorer” and go to the repository where the error occurred
  • Right click on the repository directory and select “Properties”
  • Open the “Security” tab and click on “Extended”
  • Change the “Owner” in the top of the window to your user account

For me this worked perfectly and I didn’t need to set the repository on the safe list of the global git configuration.