Error fatal: unsafe repository occurs when accessing a repository in Bitbucket Server
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
When accessing a repository, a 500 error is thrown with an error saying fatal: unsafe repository
, such as the one below:
Environment
- Bitbucket Server or Data Center version 7 or newer
Diagnosis
The logs show the following error:
"exited with code 128 saying: fatal: unsafe repository ('/var/atlassian/application-data/bitbucket/shared/data/repositories/ID' is owned by someone else) To add an exception for this directory, call: git config --global --add safe.directory /var/atlassian/application-data/bitbucket/shared/data/repositories/ID"
Cause
There are several possible causes for this problem:
Cause 1
There is a recent git version released that has a security update that caused this issue and you might have installed this version of git on the machine(s) where Bitbucket Server is installed.
Cause 2
Bitbucket Server was installed to be running as a different user (e.g. atlbitbucket
) but was then started as a different user (such as root
), causing file system permissions to change. Alternatively, someone may have manually changed file system permissions.
Solution
Depending on the root cause, use one of these solutions to resolve the problem:
Solution 1
Downgrade or upgrade git to a version that is not affected by the issue.
Solution 2
Change the filesystem permission to give the user who Bitbucket Server is configured to run full control and permissions on the Bitbucket Server home directory. At the same time, double-check if the correct dedicated Bitbucket user owns the bitbucket data directory.
Once done, start Bitbucket Server using the user you have granted permissions to. The How to View Detailed permissions for Bitbucket Server directory article has more detailed info about the issue.