You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何从Git LFS拉取所有文件并本地缓存以实现离线使用?

Git LFS: Pull All Files & Enable Offline Usage via Local Caching

Hey there! Let's tackle your two Git LFS questions one by one—these are super common asks when working with large files in Git, so I’ve got you covered.

1. Pulling All Git LFS Files

Depending on whether you’re working with a new or existing repo, here are the straightforward commands to grab every LFS-tracked file:

  • Cloning a new repo: Skip the two-step process and pull LFS files alongside the regular Git clone with:
    git clone --lfs <repo-url>
    
    This automatically fetches and checks out all LFS objects as part of the clone, so you don’t have to run extra commands afterward.
  • For an existing repo: If you already have the repo cloned but haven’t pulled LFS files yet, run:
    git lfs pull
    
    This combines two actions: git lfs fetch (which downloads LFS objects to your local cache) and git lfs checkout (which creates the actual file pointers in your working directory).
  • Fetching all historical LFS objects: If you need every version of LFS files from all branches, tags, and commits (not just your current checkout), use:
    git lfs fetch --all
    
    Follow this up with git lfs checkout to ensure all those cached objects are linked to your working directory.

2. Caching All LFS Files for Offline Usage

Great news—Git LFS is built with local caching in mind, so once you’ve pulled all LFS objects, you can work offline just like a regular Git repo. Here’s how to lock in that offline capability:

  • First, ensure all LFS objects are cached locally: Run git lfs fetch --all to grab every single LFS object from the remote. These get stored in your local LFS cache (default location: .git/lfs/objects).
  • Verify you have all objects: Check that no LFS files are marked as "missing" with:
    git lfs ls-files --all
    
    Any file without a * next to it is missing from your cache—if you see those, re-run git lfs fetch --all to grab them.
  • Prevent accidental cache pruning: By default, Git LFS might prune old or unused objects to save space. To keep all cached objects (critical for offline use), you can either:
    • Avoid running git lfs prune (this command deletes cached objects not referenced by any local commit)
    • Or set a config to disable automatic pruning entirely:
      git config lfs.prune.enable false
      

Once you’ve completed these steps, you can commit changes, switch branches, and work with your repo entirely offline. Git will automatically use the local LFS cache instead of reaching out to the remote. Just a quick heads-up: if you later switch to a branch with LFS files you never fetched, you’ll need to go online to grab those—but as long as you’ve fetched all objects first, offline work is smooth sailing.

内容的提问来源于stack exchange,提问作者Norman Percy

火山引擎 最新活动