Git Large File Storage
Git Large File Storage (or LFS) is a new, open-source extension to Git that aims to improve handling of large files. It does this by replacing large files in your repository—such as graphics—with simple text pointers.
Bitbucket Server includes an embedded LFS object store, allowing storage of large files without the need for an external object store.
Git LFS is disabled by default, on a per-repository basis, within Bitbucket Server.
On this page
- SSL should be configured and the Base URL should be configured to a "https" URL. While Git LFS does support SSH remotes, the actual download & upload of LFS objects is via HTTP(S). SSL configuration is not a requirement but is strongly recommended.
The user running the Bitbucket Server instance should not have the Git LFS client executable installed.
Enabling Git LFS for a repository
Git LFS is disabled by default within Bitbucket Server.
To enable Git LFS for Bitbucket Server
- Go to Repository settings > Large file storage (LFS)
- Tick the Allow LFS option.
- Save your settings.
If the Allow LFS tick box is un-selectable (greyed out) this is because the instance administrator has disabled LFS support on the instance.
Installing and using the Git LFS command line client
Git LFS aims to integrate with the standard Git workflow as seamlessly as possible.
To push your first Git LFS files to an existing repository
- Enable Git LFS support in Bitbucket Server for repository you wish to use Git LFS (see above)
- Download and install the git-lfs command line client
Install the Git LFS filters:
This adds the following lines to the
.gitconfigfile located in your home directory:
The above change applies globally, so it is not necessary to run this for each repository you work with.
Choose the file types you would like LFS to handle by executing the
git lfs trackcommand. The
git lfs trackcommand creates or updates the
.gitattributesfile in your repository.
Change to your cloned repository, then execute
git addto ensure updates to the
.gitattributesare later committed:
Add, commit, and push your changes as you normally would:
When pushed, the Git tree updates to include a pointer to the actual file content. This pointer will include the SHA256 hash of the object and its size in bytes. For example:
The object itself will be uploaded to a separate location via the Git LFS Batch API. Specifically, the object will be uploaded to an embedded LFS object store within your Bitbucket Server instance.
Disabling Git LFS for Bitbucket Server
Bitbucket Server is shipped with Git LFS support enabled on the instance by default, however it can be disabled. This will prevent upload or download of LFS objects for all repositories. It however does not delete existing LFS objects stored within Bitbucket Server.
To disable Git LFS on the entire Bitbucket Server instance
- Log in to Bitbucket Server with sysadmin permissions.
- Go to Admin > Server settings.
- Untick the Git LFS enabled option.
- Save your settings.
Embedded Object Store
Bitbucket Server includes an embedded LFS object store. Uploaded Git LFS objects are stored in the directory
$BITBUCKET_HOME/shared/data/git-lfs/storage. This storage location cannot be changed, as for clustered deployments it is critical that LFS object storage reside on the
shared filesystem so it is globally visible to all cluster nodes.
LFS enabled repositories support forking and a full fork-based workflow including pull requests between forks and fork synchronization. Forking is implemented through sharing of objects between fork and origin repositories and as such forks are lightweight. This means creating a fork is faster because objects are not duplicated when a fork is created.
Resolution of merge conflicts is slightly different from the non-LFS case, specifically where a merge conflict exists between two LFS objects. Since the Git repository simply contains an LFS pointer, conflict resolution must be performed with the conflicted pointer file.
Such a conflict might look like this:
Users are still required to resolve the merge conflict manually using the comment line Git client, as they normally would. The merge strategy, since this is only a pointer, can only be an ours or theirs based strategy, keeping one or the two pairs (oid/size). When resolving the conflict, if the pointer file becomes corrupted it will not be recognized as an LFS file.
The Smart Mirroring feature in Bitbucket Server supports mirroring of Git LFS objects as of Bitbucket Server 4.5. Mirroring of Git LFS objects is performed on-demand; that is, when a client requests download of a Git LFS object from the mirror node, the object will be streamed from the upstream node if it is not already available on the mirror. Subsequent downloads of the same object will be downloaded directly from the copy stored on the mirror.
Limiting Disk Space Usage
By default Bitbucket Server will not permit any further Git LFS uploads if the amount of free disk space in the filesystem that hosts the storage directory has less than 100 megabytes of free disk space. When a client attempts to upload (via a Git push) an LFS file that would result in the free disk-space threshold being exceeded, an error message indicating as such is sent to the client:
A warning will also be logged in the
atlassian-bitbucket.log file. For example:
The free disk-space threshold can be tuned by adding the following property to the Bitbucket Server config properties file (this example tunes the threshold to one gigabyte, and note that this value is in bytes):
Setting the value to zero will disable the free disk space check and will allow files to be uploaded even if doing so would exhaust all available disk space. This however is not encouraged, it can lead to situations where the system exhausts all disk space but is unable to log error messages stating the same (because the disk is full), leading to difficulties debugging problems that are caused by disk space exhaustion.
A Bitbucket Server restart is required for the change to take effect.
Limiting Network Connections
Large Git LFS download or upload operations over very slow network links could take many minutes, or even hours. Bitbucket Server supports a finite number of HTTP connections via Tomcat (by default 150). If Git LFS were permitted to exhaust this connection pool then the user interface, Git hosting, and REST API access could be impacted. For this reason a default limit of 80 concurrent Git LFS connections are permitted. This limit can be increased or decreased if necessary by overriding the
throttle.resource.git-lfs= setting in the Bitbucket Server config properties file. A Bitbucket Server restart is required for the change to take effect.
When a client makes a request to upload or download an object, and the request would exceed the maximum number of concurrent connections, a HTTP status 503 is returned, and this error is sent to the client:
atlassian-bitbucket.log file will also contain an associated warning:
Was this helpful?
Thanks for your feedback!