Search code examples
gitbitbucketbitbucket-servergit-lfs

Why is Bibucket Server storing LFS objects locally?


I've set up Bitbucket Server wit PostgreSQL db successfully, but I have a problem with LFS. I did everything according to this guide. At first it seems to work as there are no errors when pushing or pulling. The problem is that the LFS files are stored locally in my repo and on the server at the same time. What can be causing this issue?


Solution

  • (This is based on the comments discussion, but we've reached the point where I think I see what you're asking and the answer might be a bit unwieldy in further comments...)


    It is true that git LFS can reduce the local storage used for large files in some situations, but it's probably more useful to think of it as primarily trying to save unnecessary transfer of large files, with the potential added benefit of reducing local storage.

    As with core git, all data for what's currently checked out has to be kept locally[1]. Unlike core git, you don't have to keep local copies of all files used throughout history. The two ways to not have a local copy of a large file that's in the repo's LFS store are:

    1) Someone else added the file, and you never checked out any commit that used it

    2) After checking out something that doesn't depend on some of the files, you removed them (by running git lfs prune preferably)

    LFS does have rules for what it thinks you're likely to need locally ("recent commits", "recent branches", etc.). These can be tuned via configuration. The git lfs manual pages probably spell it out better than I can (https://github.com/git-lfs/git-lfs/tree/master/docs/man). I'd start with the prune and fetch pages.

    LFS doesn't like to automatically prune the store, because it thinks it's likely that you might have multiple repos sharing an LFS store and doesn't want to make assumptions.

    So for those reasons, if your expectation is that LFS will free up local storage, it may seem to not be working. But if you have an existing repo with large files and a large history (deep history and/or many branches), then you'll find that time to clone such a repo is greatly improved - and that's really the starting point for understanding what LFS wants to do for you.

    So to summarize:

    • If you want to free up local storage, you need to tell lfs to prune the local store

    • prune will still keep things it thinks you might need (determined in part by your configuration)

    • What's currently checked out is always kept locally.


    [1] Of course in either case, "locally" means "local as far as git knows"; you could use a remote filesystem if you really want to store the files elsewhere, but in many use cases you might find this just shoots you in the foot.