Back to Git & Dev Tools
2025-12-176 min read

Moving a Git LFS repository between hosts (Git & Dev Tools)

Learn Moving a Git LFS repository between hosts (Git & Dev Tools) step by step with clear examples and exercises.

Why This Matters

Migrating a Git Large File Storage (LFS) repository between hosts is an essential skill for developers working on large projects that involve managing files such as videos, audio files, or binary data. In this guide, we will walk you through the process of moving a Git LFS repository between hosts, providing practical insights and real-world examples to help you navigate potential issues.

By understanding how to move a Git LFS repository between hosts, developers can maintain a smooth workflow, ensure consistency across different hosts, and avoid common pitfalls that may arise when dealing with large files.

Prerequisites

To follow this guide, you should have a basic understanding of:

  1. Git: Familiarity with Git commands like git init, git add, git commit, and git pull.
  2. Git LFS: Knowledge of how to initialize, configure, and use Git Large File Storage.
  3. SSH Keys: Ability to generate and manage SSH keys for secure file transfers between hosts.
  4. Basic understanding of the terminal or command line interface.
  5. Understanding of how to clone a repository using git clone command.
  6. Familiarity with navigating directories in the terminal or command line interface.
  7. Knowledge of how to checkout specific branches or commits using git checkout command.
  8. Understanding of how to commit and push changes to a repository.

Core Concept

Initializing Git LFS

Before moving a Git LFS repository, you need to ensure that both the source and destination repositories have Git LFS installed. To install Git LFS on your local machine, run:

curl -s https://packageurl.io/install | sh

After installation, initialize Git LFS in your repository by running:

git lfs install

Configuring Git LFS

To configure Git LFS for specific file types, create a .gitattributes file in the root directory of your repository and add the following line:

*.[extension] filter=lfs merge=lfs-merge

Replace [extension] with the appropriate file extension (e.g., .mp4 for video files). This tells Git LFS to manage these files using its own mechanisms.

Moving a Git LFS Repository

To move a Git LFS repository between hosts, follow these steps:

  1. Clone the source repository: On your destination host, clone the source repository using git clone .
  2. Navigate to the cloned repository: Use cd to navigate to the cloned repository on your destination host.
  3. Pull all changes: Make sure that both the source and destination repositories are up-to-date by running git pull origin main (or replace 'main' with the appropriate branch name).
  4. Check if Git LFS is initialized in the cloned repository: Run git lfs version to verify that Git LFS is installed and working correctly in the cloned repository. If not, re-initialize Git LFS using the command git lfs install.
  5. Copy the .git directory: Navigate to the root directory of your source repository and copy the .git folder using cp -R .git /path/to/destination/repository.
  6. Checkout the correct branch or commit: Use git checkout [branch_name] or git checkout [commit_hash] to ensure that you have the correct version of the repository on your destination host.
  7. Pull large files: Run git lfs pull to download large files from the source repository to the destination host.
  8. Commit and push changes: After pulling large files, commit them using git add ., git commit -m "Moved Git LFS repository", and git push.
  9. Update remote repository references: If you are moving the repository to a new remote, update the remote URL using git remote set-url origin .

Worked Example

Let's walk through an example of moving a Git LFS repository between hosts:

  1. Source Repository (Host A): Initialize Git LFS, create a video file with the extension .mp4, add it to the repository, commit and push changes.
  2. Destination Repository (Host B): Clone the source repository using git clone , navigate to the cloned repository, pull all changes, check if Git LFS is initialized in the cloned repository, copy the .git folder, checkout the correct branch or commit, pull large files, commit and push changes, update remote repository references (if necessary).

Common Mistakes

  1. Not initializing Git LFS on the destination host: This will result in errors when trying to access large files.
  2. Skipping the git lfs pull command: Failing to pull large files from the source repository may cause issues with the destination repository.
  3. Not committing and pushing changes after pulling large files: This step is essential for updating the destination repository with the downloaded files.
  4. Using HTTP instead of SSH for file transfers: Using HTTP can lead to security vulnerabilities, as it transmits data in plain text. It's recommended to use SSH for secure file transfers.
  5. Not ensuring that both the source and destination repositories are up-to-date before copying the .git directory: This could result in data loss or inconsistencies between the two repositories.
  6. Not using the correct Git LFS command to pull large files (git lfs pull): Using regular git pull will not download large files stored with Git LFS.
  7. Not handling SSH key permissions correctly: Incorrect SSH key permissions on either the source or destination hosts can cause authentication issues during the file transfer process.
  8. Not properly updating remote repository references: If moving the repository to a new remote, ensure that you update the remote URL using git remote set-url origin .

Practice Questions

  1. What command initializes Git LFS on a local machine?
  2. How do you configure Git LFS to manage specific file types?
  3. What steps are involved in moving a Git LFS repository between hosts?
  4. Why is it important to pull large files after cloning the source repository?
  5. What happens if you skip the git lfs install command on the destination host?
  6. What command should be used to download large files from the source repository to the destination host?
  7. How can incorrect SSH key permissions affect the file transfer process when moving a Git LFS repository between hosts?
  8. If you are moving the repository to a new remote, what command should be used to update the remote URL?

FAQ

Q: Can I move a Git LFS repository without copying the .git folder?

A: No, moving a Git LFS repository requires copying the .git folder to ensure that large files are properly managed.

Q: What command should be used to check if Git LFS is initialized in a repository?

A: To verify that Git LFS is installed and working correctly in a repository, run git lfs version.

Q: Can I use Git LFS with both SSH and HTTP for file transfers?

A: While it's possible, using HTTP can lead to security vulnerabilities, as it transmits data in plain text. It's recommended to use SSH for secure file transfers.

Q: Can I move a Git LFS repository between hosts without generating SSH keys?

A: No, using SSH keys is essential for secure file transfers between hosts when moving a Git LFS repository.

Q: What should I do if I encounter authentication issues during the file transfer process when moving a Git LFS repository between hosts?

A: Check your SSH key permissions and ensure that you have correctly configured your SSH agent or added your SSH key to the appropriate ssh-agent or ssh-config files.

Q: What happens if I try to move a Git LFS repository without initializing Git LFS on the destination host?

A: You will encounter errors when trying to access large files in the destination repository.

Moving a Git LFS repository between hosts (Git & Dev Tools) | Git & Dev Tools | XQA Learn