Users not able to delete branches error -- File exists

Still need help?

The Atlassian Community is here for you.

Ask the community

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



When attempting to delete or create a branch an error occurs shows an error that states:

remote: error: unable to create file <bitbucketHome>/shared/data/repositories/<repoID>/./ File exists


This an example screen shot:
Screen Shot 2021-01-26 at 8.17.19 AM.png


The file exists in the git repository.  This file is used by git to provide a temporary file for the new pack and warn other git process that the pack is running. Git will create this file,, put all of the references in this file, remove all of the loose references, them move the file to packed-refs.  The file format is <CommitHash>, then followed by the branch name.

If the normal process is interrupted, this file can be left around.  This can happen if a git pack-refs process was killed while packing.  


Remove the file.  Here is the process to remove the file without any further data loss.  This assumes that all Bitbucket Data Center Nodes have confirmed that the file is not being accessed.  Run this command on each Bitbucket Data Center Node.  No output means that the file is not being used if the full path of the file is like the above error.   OR do a rolling restart of each Bitbucket Data Center Node if you are unsure.

sudo lsof | grep "" file is empty

It is safe to delete this file.  file is not empty

If you are unsure about any of these steps, please stop and contact support before step 9.

  1. Stop all Bitbucket Server or each Bitbucket Data Center Node.

  2. Move the file to a temp directory:
    • mv <path>/ /tmp
  3. Copy the packed-refs file from the repository and check to see if there are any valid refs in that are not in packed-refs
    • cp <pathToRepo>/packed-refs /tmp
      diff /tmp/ /tmp/packed-refs
  4. Make a copy of the git repository.
    • cp -r <path> /tmp
  5. For each hash in make sure the reference is a valid commit.  Make a list of lines that have valid hashes.  If git log does not find a corresponding commit hash, you should not use that hash in the updated file. 
    • cd /tmp/<dir>/
      git log <hash>
  6. Add the missing lines to the original packed-refs file in /tmp.

  7. Copy the corrected packed-refs into the repository copy.
    • cp /tmp/packed-refs /tmp/<dir>/
  8. Run the pack refs and git fsck command to make sure the packed-refs file is valid.  If any errors, do not continue.  This step must pass to continue.
  9. Move the updated pack-refs file to the original repository.
    • cp /tmp/packed-refs <pathToRepo>/
  10. Start Bitbucket. 

Last modified on Jan 29, 2021

Was this helpful?

Provide feedback about this article
Powered by Confluence and Scroll Viewport.