Skip to content

FAQ: Migrating Binaries to `Git LFS`

Ulrond edited this page Jul 15, 2024 · 1 revision

Here's an overview of migrating binaries to Git LFS (Large File Storage) from the current tip of your branch, along with considerations and best practices:

Understanding Git LFS

Git LFS is a Git extension designed to handle large files more efficiently. Instead of storing the entire file contents directly in your Git repository (which can bloat it over time), LFS replaces large files with small text pointers. The actual file content is stored in a separate LFS store, typically on a remote server.

Why Migrate to LFS?

  • Smaller Repository Size: LFS drastically reduces the size of your repository, making cloning, fetching, and pushing much faster.
  • Improved Performance: Since Git only needs to manage lightweight pointers, common operations are more efficient.
  • Storage Optimization: LFS servers often have storage optimizations specifically for large files.

Migration Steps

  1. Install Git LFS: Ensure Git LFS is installed and set up on your system.

  2. Track File Types: Tell Git LFS which file types to track. Create or update your .gitattributes file in the root of your repository:

    *.jpg filter=lfs diff=lfs merge=lfs -text
    *.png filter=lfs diff=lfs merge=lfs -text
    *.zip filter=lfs diff=lfs merge=lfs -text
    

    (Replace the examples with your specific binary file types)

  3. Migrate Existing Files:

    git lfs migrate import --include="*.jpg" --include="*.png" --include="*.zip"

    (Replace the examples with the file types you want to migrate)

  4. Commit Changes:

    git add .gitattributes
    git commit -m "Migrate binaries to LFS"
  5. Push to Remote: Push your changes, including the updated .gitattributes file, to your remote repository.

Important Considerations

  • Existing Clones: Collaborators who have already cloned the repository will need to fetch the LFS pointers and the actual files from the LFS store after you've migrated. They might need to run git lfs fetch and git lfs checkout.

  • Large Repositories: If you have a very large repository, the migration might take some time. You can use the --verbose flag to see progress:

     git lfs migrate import --verbose --include="*.jpg"
  • File Locking: Consider using Git LFS file locking (git lfs locks) if you have large binary files that are often edited concurrently by multiple people. This can prevent merge conflicts.

  • Bandwidth Considerations: Be mindful of the potential network traffic involved in transferring large files to the LFS store.

Example: Migrating a Single File

If you only want to migrate a single file from the current tip of your branch, you can use:

git lfs track "your_file.bin" 
git add your_file.bin
git commit -m "Add your_file.bin to LFS"
Clone this wiki locally