LinuxCommandLibrary

git-lfs

Manage large files in Git repositories

TLDR

Initialize Git LFS

$ git lfs install
copy

Track files that match a glob
$ git lfs track '[*.bin]'
copy

Change the Git LFS endpoint URL (useful if the LFS server is separate from the Git server)
$ git config [[-f|--file]] .lfsconfig lfs.url [lfs_endpoint_url]
copy

List tracked patterns
$ git lfs track
copy

List tracked files that have been committed
$ git lfs ls-files
copy

Push all Git LFS objects to the remote server (useful if errors are encountered)
$ git lfs push --all [remote_name] [branch_name]
copy

Fetch all Git LFS objects
$ git lfs fetch
copy

Replace pointer files with actual Git LFS objects
$ git lfs checkout
copy

SYNOPSIS

git lfs [<options>] <command> [<args>]

PARAMETERS

-h, --help
    Show help for the command

-v, --version
    Print Git LFS version

--debug
    Enable debug logging

install
    Install LFS hooks in current Git repo

track <pattern>
    Track files matching pattern with LFS

untrack <pattern>
    Stop tracking files with LFS

lock [<file>]
    Lock file(s) to prevent concurrent edits

unlock [<file>]
    Unlock file(s)

push [<remote>]
    Push LFS objects to remote

pull [<remote>]
    Pull LFS objects from remote

fetch [<remote>]
    Fetch LFS objects without checking out

checkout
    Update working tree with LFS files

ls-files
    List LFS-tracked files

status
    Show status of LFS-tracked files

prune
    Delete unused LFS objects locally

migrate
    Migrate Git history to/from LFS

DESCRIPTION

Git LFS (Large File Storage) is a command-line tool extending Git to handle large files efficiently. It replaces large files in the repository with tiny pointer files containing metadata, while storing actual file contents on a remote LFS server.

Usage begins with git lfs install, which sets up Git hooks for smudge (checkout) and clean (checkin) filters. Track files via git lfs track '*.zip', creating .gitattributes entries. When committing tracked files, Git LFS uploads them to the server; clones download pointers first, fetching content on demand with git lfs pull or hooks.

Supports features like file locking to prevent edit conflicts, pruning unused objects, and migration of existing repos. Requires server-side support (e.g., GitHub, GitLab). Ideal for binaries, media, datasets—keeps Git repos lightweight and fast.

CAVEATS

Requires LFS-compatible server (e.g., GitHub). Does not reduce server storage; files consume space there. Hooks must be installed per repo/clone.

EXAMPLE WORKFLOW

git lfs install
git lfs track '*.psd'
git add .gitattributes large.psd
git commit -m 'Add PSD'
git push

ENVIRONMENT VARS

GIT_LFS_SKIP_SMUDGE=1 (skip file download on checkout).
GIT_LFS_FORCE_SKD_SMUDGE=1 (force download).

HISTORY

Announced by GitHub in 2015; initial release v0.5. Development by GitHub, Atlassian, Basecamp. Now at v3.x, integrated in most Git hosts.

SEE ALSO

git(1), gitattributes(5), git-config(5)

Copied to clipboard