Accessing a repository is returning "A Git repository could not be found" error
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. 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
Accessing a repository page; <Base URL>/projects/<Project Key>/repos/<Repo Key>/browse
, returns an error in the UI stating A Git repository could not be found
.
Environment
Bitbucket Server/DC
Diagnosis
The following error message can be found in the
atlassian-bitbucket.log
file:2021-08-15 14:50:25,188 ERROR [http-nio-7990-exec-5] admin @NF98V3x884x191x0 100fu7j 10.64.31.110,10.70.74.168 "GET /projects/TEST/repos/testrepo/browse HTTP/1.1" c.a.s.i.w.HandlerExceptionResolverImpl A Git repository could not be found. com.atlassian.bitbucket.scm.CommandFailedException: A Git repository could not be found. at com.atlassian.bitbucket.scm.git.command.GitCommandExitHandler.evaluateStdErr(GitCommandExitHandler.java:72) at com.atlassian.bitbucket.scm.git.command.GitCommandExitHandler.onError(GitCommandExitHandler.java:204) at com.atlassian.bitbucket.scm.DefaultCommandExitHandler.onExit(DefaultCommandExitHandler.java:32) at com.atlassian.bitbucket.scm.BaseCommand.callExitHandler(BaseCommand.java:214) at com.atlassian.bitbucket.scm.BaseCommand$CommandFuture.internalGet(BaseCommand.java:348) at com.atlassian.bitbucket.scm.BaseCommand$CommandFuture.get(BaseCommand.java:312) ... ... 317 frames trimmed
git fsck
returns the following:$ git fsck fatal: not a git repository (or any of the parent directories): .git
This type of error is one that git throws when it's asked to perform a git operation against a directory that is not a git repository. This likely means that one of two things is the case. Either:
- The git command is being executed against a directory that doesn't match the expected directory where the repository is located on the filesystem. Alternatively, if the Bitbucket service account has not been granted filesystem access to any of the needed git metadata files in that directory then we could see this same error.
OR
- The directory is correct, but the hidden files and directories within that directory (such as the .git directory that contains the repository metadata) are not present, leading to the repository being treated as though it were not a git repository when git tries to run against it.
Cause
Repository content was copied from a different file system
- Steps could involve copy via the Operating System GUI or command line (such as
cp
orscp
).
The backup of the instance was created using AWS native tools
The backup of the instance was created using AWS native tools to perform snapshots from filesystem + database backup and restore. Basically, the steps taken were:
- Stop Bitbucket.
Copied the shared folder to a new instance by using a command similar to the following:
aws commandaws s3 cp <<path-to-shared-folder>> s3://<test-atlassian-backup-bucket>/bitbucket/shared/<date>
At the same time, it was copied a snapshot of the production instance RDS DB.
Restored the DB in the test DB instance using the snapshot above.
Based on that, the scenario currently described in the Diagnosis section is dealing with the latter - as the above command will not copy an entire directory.
Solution
- For copying the repository content directly from the filesystem, it's recommended to use
rsync
with the--delete
flag. - When performing snapshots of AWS, it should be used the --recursive flag. You should take a new backup and use a tar command to create a single tar.gz file that contains the entire shared folder structure, empty directories, and all inside the shared directory.
We always encourage you to use the steps in the How to establish staging server environments for Bitbucket Server - Bitbucket Data Center and Server article to construct a new test environment. This is our tried and true method for successfully completing a refresh of a non-prod environment.