Unable to create packed-refs.lock: File exists on Bitbucket Data Center

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

The Git push or delete branch is failing with the below error as there is an ongoing operation already taking place in the repository or the packed-refs.lock file was somehow left behind by the Bitbucket process without being cleaned up.

1 2 3 4 5 6 7 8 9 remote: error: Unable to create '<BITBUCKET_HOME>shared/data/repositories/12/./packed-refs.lock': File exists. remote: Another git process seems to be running in this repository, e.g. remote: an editor opened by 'git commit'. Please make sure all processes remote: are terminated then try again. If it still fails, a git process remote: may have crashed in this repository earlier: remote: remove the file manually to continue. To ssh://stash.test.com/scm/test/test.git ! [remote rejected] fix/test-refresh-fix (failed to update ref) error: failed to push some refs to 'ssh://stash.test.com/scm/test/test.git'

Environment

Bitbucket Data Center Version 7.x.

Diagnosis

Check if the packed-refs.lock is being used by some processes by running the following command on all the Bitbucket Nodes

1 sudo lsof | grep "packed-refs.lock"

If the above command gives an output that matches the path "<BITBUCKET_HOME>shared/data/repositories/12/./packed-refs.lock" then it confirms that some process is still ongoing in that repository.

However, if it doesn't return anything, it indicates that the file is stale and can be safely removed.

Cause

The issue stems from the stale packed-refs.lock file, which is left behind by the Bitbucket backend Git process. This might occur if Bitbucket Service was forcefully closed during active operations, or if the shared filesystem was unmounted unexpectedly while Bitbucket was running, or if the Bitbucket server was forcefully rebooted while a Bitbucket process was in progress.

Solution

⚠️ Before making any changes, please back up the repository<BITBUCKET_HOME>shared/data/repositories/<repo_id>/ on the Bitbucket server's file system itself so that you can restore it in case anything goes wrong ⚠️

After taking the backup, move the file "<BITBUCKET_HOME>shared/data/repositories/12/./packed-refs.lock" out of the "<BITBUCKET_HOME>shared/data/repositories/12/" repository directory and then try to push again.

Updated on April 24, 2025

Still need help?

The Atlassian Community is here for you.