SourceTree being overzealous

7 November 2024

I came across this strange git error while trying to check out my dependencies with cargo.

fatal: cannot use bare repository '/Users/tk/.cargo/git/db/tracing-3b3ea2e46aa0049f' (safe.bareRepository is 'explicit')
error: failed to load source for dependency `tracing`

This odd error turned out to be caused by SourceTree, the git client I use on my work Mac. For overenthusiastic security reasons, it modifies ~./gitconfig like this, which disables the use of bare repositories that are not explicitly named:

[safe]
    bareRepository = explicit

Unfortunately this breaks how cargo uses dependencies in git repos. I resolved this by removing the entry from ~/.gitconfig and adjusting the setting mentioned in the ticket:

You could disable auto-pushing this setting in your config in Sourcetree settings by opening Sourcetree -> Settings... and unchecking "Allow Sourcetree to modify your global Mercurial and Git configuration files".