Users not able to delete branches error -- packed-refs.new: 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.

    

Summary

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>/./packed-refs.new: File exists

Diagnosis

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

Cause

The file packed-refs.new 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, packed-refs.new, 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.  

Solution

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 "packed-refs.new"


packed-refs.new file is empty

It is safe to delete this file.

packed-refs.new  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 packed-refs.new to a temp directory:
    • mv <path>/packed-refs.new /tmp
  3. Copy the packed-refs file from the repository and check to see if there are any valid refs in packed-refs.new that are not in packed-refs
    • cp <pathToRepo>/packed-refs /tmp
      diff /tmp/packed-refs.new /tmp/packed-refs
  4. Make a copy of the git repository.
    • cp -r <path> /tmp
  5. For each hash in packed-refs.new 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?

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