Sub topic 7
Cloning and Fetching LFS Content, Including Partial Downloads
This chapter assumes you can clone, fetch, pull, and push with Git, and that you know what a Git LFS pointer file is. You should also have Git LFS installed with git lfs install already run for your user.
What happens during a normal clone
When you run git clone on a repository that uses LFS, Git first downloads the regular history. That history contains only small pointer files for the tracked paths. As Git checks out the working tree, the LFS smudge filter reads each pointer and downloads the matching object from the LFS server. The working tree ends up with real files.
If LFS is not installed, the checkout finishes without the smudge step. You get pointer files with no error message. The troubleshooting chapter covers that case. Here we focus on controlling when and how much content is downloaded.
Fetch, checkout, and pull
Three commands separate the steps that a clone performs together.
| Command | What it does |
|---|---|
| `git lfs fetch` | Downloads LFS objects into the local cache in `.git/lfs`. It does not change your working tree. |
| `git lfs checkout` | Replaces pointer files in the working tree with real content from the local cache. |
| `git lfs pull` | Runs `git lfs fetch` followed by `git lfs checkout`. |
Plain git fetch and git pull also download LFS objects for the commits they bring in, as long as the LFS hooks and filters are installed. The explicit git lfs commands are useful when you want to repair a checkout or download content in stages.
Partial downloads
Some repositories hold many gigabytes of assets, and you may need only a few directories. The approach is to clone without downloading LFS content, then pull only what you need.
Setting GIT_LFS_SKIP_SMUDGE=1 disables the smudge filter for that command. The clone finishes quickly and leaves pointer files in the working tree. Then git lfs pull --include downloads the content for the paths you name.
GIT_LFS_SKIP_SMUDGE=1 git clone https://example.com/team/assets.git
cd assets
git lfs pull --include="textures/"The --include option takes a comma-separated list of path patterns. Its counterpart --exclude removes paths from the set. You can combine them:
git lfs pull --include="textures/,models/" --exclude="models/archive/"Files outside the selected paths stay as pointer files. Opening one in an application gives you a small text file, not an image or a model. Run git lfs pull with a wider --include when you need more.
Fetching other branches and history
By default, git lfs fetch downloads objects for the commit you currently have checked out. It also fetches objects for recent history on other refs. The recent window is controlled by lfs.fetchrecentrefsdays (default 7) and related settings. To get everything, use:
git lfs fetch --allThis downloads every LFS object reachable from every ref. Use it before mirroring a repository or working offline, and expect large transfers.
Checking what is missing
git lfs ls-files lists the files LFS manages. A * after the object ID means the content is present locally. A - means only the pointer is present. This is the quickest way to confirm what a partial clone has downloaded.
Exercise
Exercise
You cloned a 40 GB asset repository with GIT_LFS_SKIP_SMUDGE=1. You now need only the files under audio/voices/. Which command downloads them, and how can you confirm afterward that other directories are still pointers?
Show answer
Run git lfs pull --include="audio/voices/". Then run git lfs ls-files. Files under audio/voices/ show * after the object ID, and files elsewhere show -, which means only the pointer is present.
Exercise
What is the difference between git lfs fetch and git lfs pull?
Show answer
git lfs fetch only downloads objects into the local cache in .git/lfs. git lfs pull does that and then runs git lfs checkout, which replaces pointer files in the working tree with the real content.