Fatal: cannot use bare repository

Hi there, that's my first post.

There is an ongoing issue (at least I believe it to be ongoing) where some developers start to have issue fetching swift packages via SPM.

There is a opened thread on Apple Forum about it, and support recommended to post on Swift Forum.
https://forums.developer.apple.com/forums/thread/747070?answerId=810504022#810504022

It seems this issue is reproducible whether via XCode SPM window or via command line.

The temporary solution that some developers found and that I can confirm works is to remove the following from ~/.gitconfig

[safe]
    bareRepository = explicit

The above is a solution, but I think most developers will hit their head on a wall before figuring this out.

Thank you in advance for anyone able to help.

12 Likes

Thank you for posting this - I can confirm I'm also experiencing the same issue and the same workaround cleared it up for me.

Edited to add: Seems relevant that I had just updated SourceTree when this started happening.

1 Like

I upgraded SourceTree this morning and the problem started. The upgrade added:

[safe]
    bareRepository = explicit

to ~/.gitconfig. Removed it and Xcode worked again.

A bug has been filed with Atlassian. https://jira.atlassian.com/browse/SRCTREE-8176

8 Likes

Thanks eholley! I remember updating SourceTree last week or so. Actually, just before deleting it to use lazygit instead :smile:

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)

just having this problem since this morning, checking this and solve the problem! thank you

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".

2 Likes

I had the same issue.

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...

This is a security restriction that prevents cve-2022-24765.

Basically, I create a Git hook, let other users access, then the hook will execute with the permissions of other users.

Any of the following solutions will fix it:

  1. Disable this security feature for all folders if your machine is single user.
git config --global --add safe.directory '*'
  1. Or disable it for some folder
git config --global --add safe.directory '/some/folder'
  1. Or prevent Sourcetree from adding this restriction by not allowing modification of your ~/.gitconfig
1 Like

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.

1 Like

I had the same problem as you. What I did:

  • Updated Sourcetree
  • Deleted Derived Data

Issue got fixed. I can't really say it'll work for sure because the error seemed totally random.