How to solve "detected dubious ownership in repository" when "directory = *" does not seem to have any effect

The issue

This week me and my team started to get a weird git message

fatal: detected dubious ownership in repository [directory]

that basically did not allow us to pull nor push changes.

 

The simple solution that did not work

Most of the issues seemed Windows related and I was on Kubuntu, but I assumed that the operating system would not be a point of interest, which, in the end, proved to be correct.

All solutions pointed to the execution of a simple command

git config --global --add safe.directory [directory]

which would, simply, add the [directory] to the ~/.gitconfig file and that would mark the [directory] as being trusted and thus solving the issue. A more simple approach would be using * as the [directory], basically saying any directory.

And that was the road that I took. But with no success. I even tried --system instead of --global which would set that configuration at the system level (in /etc directory) instead of the making it only available to the user.

I ended up with a ~/.gitconfig file like this:

[user]
       email = m6@blogger.com
       name = M6
[safe]
       directory = *

But nothing seemed to work.


The suspicious directory

Early on, I did notice something weird. The [directory] presented in the solutions referred to local paths, but the [directory] I was getting was the repository server path.

If it was a local issue, the [directory] would be something like /home/m6/work/repo_project but I was getting /var/git/repo_project, which only exists on the repository server.

While doing the investigation, I did came across with a project that was working fine! This raised my doubts about that local ~/.gitconfig file being if any use since the that particular repository worked fine with, or without that file being present on the system.


The solution

I logged on the repository server and checked that my user had a ~/.gitconfig file present with the directory parameter pointing precisely to the path of the only project that was working fine.

I changed the value *, which means any path, gave it a try and suddenly the problem was solved for me.

I checked with my team and since the server is solely dedicated to be a git repository server, most of the people do not have a real home in the system since they do not have the need to work on the server.

The solution for the team users that do not have a home was to create a dummy /home/gitdummy directory, create a .gitconfig file holding

[safe]
       directory = *

and finally change the users home in the /etc/passwd file pointing it to /home/gitdummy.


Summary

In short, if you run into this issue and the straight forward solution does not seem to work for you as it did not for me, check where the path is located, enter on that system and add

[safe]
       directory = *

to the ~/.gitconfig file of your user.

If you run into a transversal issue affecting all users of that system, just apply that solution to all of them.

If the users do not have a home on that system, create a dummy home and point the users home to it.


./M6

Percentage Difference Calculator

While looking for a mathematical formula, I came across this Percentage Difference Calculator.
The solution is performed step by step and it has a detailed explanation about the formula.


./M6