Skip to content
Search

Git Large File Storage

lastmod 2026-02-24created 2015-10-0129 edits

An open source Git extension for versioning large files

Git Large File Storage (LFS) replaces large files such as audio samples, videos, datasets, and graphics with text pointers inside Git, while storing the file contents on a remote server like GitHub.com or GitHub Enterprise.

Git_Large_File_Storage_-_graphic.gif

How to install

  • Homebrew: brew install git-lfs
  • MacPorts: port install git-lfs

DEB

$ curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
$ sudo apt-get install git-lfs

Ubuntu

$ sudo apt install git-lfs

Getting Started

Download and install the Git command line extension. You only have to set up Git LFS once.

$ git lfs install

Select the file types you'd like Git LFS to manage (or directly edit your .gitattributes). You can configure additional file extensions at anytime.

$ git lfs track "*.psd"

There is no step three. Just commit and push to GitHub as you normally would.

$ git add file.psd
$ git commit -m "Add design file"
$ git push origin master

LFS Pull

To fetch data from an external repository, enter the following.

$ git lfs pull

Uninstalling LFS

git lfs uninstall

LFS file list

$ git lfs ls-files --all
2383379170 * recc_daemon_vision/seven_segment/ckps/faster_rcnn_r50_fpn_1x_coco_211006/seven_segment_20211007.pth
70eacdbba1 * recc_daemon_vision/seven_segment/ckps/faster_rcnn_r50_fpn_1x_coco_211006/seven_segment_20211028_adam.pth
c51b851e57 * recc_daemon_vision_tester/samples/ssd_sample_01.jpg

Checking the list of files managed by LFS

git lfs ls-files --all

Untracking git lfs in all commits

Untrack all files from git lfs

git lfs migrate export --everything --include .

Untrack files with the .ext extension from git lfs

git lfs migrate export --everything --include='*.ext'

WARNING

Takes a while

Removing objects from LFS

To remove objects from LFS:

  • Remove the objects from the repository using git filter-repo.
  • Delete the related LFS lines for the removed objects from the .gitattributes file and commit the change.
  • git lfs uninstall - removes the lfs hooks

Removing the .gitattributes file from commit history

git filter-branch -f --prune-empty --tree-filter 'git rm -f .gitattributes --ignore-unmatch' --tag-name-filter cat -- --all

Checking staging status

$ $ git lfs status
On branch master
Git LFS objects to be pushed to origin/master:


Git LFS objects to be committed:

        cvtoolkit/apps/kra/__init__.py (Git: e3b0c44)
        cvtoolkit/apps/kra/kra.py (Git: a9a96b0)
        cvtoolkit/arguments.py (Git: 3bf1b06 -> Git: b67e097)
        cvtoolkit/assets/__init__.py (Git: dd1bf6e -> Git: 573d2e3)
        cvtoolkit/assets/videos/kra/20230428-front1.mp4 (LFS: 52a6923)
        cvtoolkit/assets/videos/kra/20230428-front2.mp4 (LFS: ac3d2fe)
        cvtoolkit/assets/videos/kra/20230428-front3.mp4 (LFS: 384df63)
        cvtoolkit/assets/videos/kra/20230428-front4.mp4 (LFS: ad05f4a)
        cvtoolkit/entrypoint.py (Git: beab68d -> Git: 243c233)

Git LFS objects not staged for commit:

Freeing up storage

Meaning of -text in .gitattribute

-text means unsetting the text attribute.

# Treat *.otf as **not** text
*.otf filter=lfs diff=lfs merge=lfs -text

# Treat *.otf as text
*.otf filter=lfs diff=lfs merge=lfs text

If you omit -text, the default set in the .gitattributes file is used. So it is better to keep -text.

Config file

Description of the .lfsconfig file

Troubleshooting

git-lfs-authenticate (Errno::ENOENT)

A bug like the following can occur.

$ git lfs pull
Git LFS: (0 of 8 files) 0 B / 855.26 MB                                                              
batch request: exit status 1: /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_shell.rb:143:in `exec': No such file or directory - git-lfs-authenticate (Errno::ENOENT)
    from /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_shell.rb:143:in `exec_cmd'
    from /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_shell.rb:117:in `process_cmd'
    from /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_shell.rb:35:in `exec'
    from /opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-shell:24:in `<main>'

In this case, the problem may be caused by a missing LFS URL. Add the URL as follows.

$ git config lfs.url http://gitlab.com/user/repo.git/info/lfs

For reference, in the case of GitLab, write the URL like http://host/user/repo.git/info/lfs.

As a result, the information is written to the .git/config file in the following format.

[lfs]
    url = "http://server/proj/americano.git/info/lfs"
[lfs "http://server/proj/americano.git/info/lfs"]
    access = basic

See also

Favorite site

author Zer0 sitemap