Unable to create packed-refs.lock: File exists on Bitbucket Data Center
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
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.
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
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.