I was getting started for the first time on SPM yesterday and didn't understand the errors I was getting when trying to consume the package I created. Spent a day hitting my head on a wall... Thank you @minoo555!!
I just had this issue too and it was SourceTree that added the bareRepository = explicit that made it not work (see the link to the Atlassian bug posted above)
Deleting this won't solve the problem - Sourcetree will add it next time you use it. You also need to go to Settings in Sourcetree and deselect "Allow Sourcetree to modify your global Mercurial and Git configuration files".
Removing the bareRepository = explicit line from ~/.gitconfig did solve it temporarily, but as @lukaszciastko mentioned SourceTree will add it back, unless you disallow that via settings.
Upgrading to latest MacOS (15.1 as we speak) did seem to solve it permanently though. Crossing fingers...
So I have checked my ~/.gitconfig and I did not have [safe] bareRepository = explicit in my config at all yet I still can't add a single package from SPM. I also tried setting git config --global --add safe.directory '*' but that did not work either.