December 12, 2024 · 4 min read · Edit on GitHub
Tagged as:
Git is an essential tool for developers, enabling collaborative version control for projects large and small. When working with large files—think high-resolution images, videos, or massive datasets—Git LFS (Large File Storage) is a lifesaver. However, the default Git LFS implementation uses HTTP for communication, which might not always fit your setup or preferences. I recently faced this issue while trying to set up Git with LFS on my own server. I wanted everything to work over SSH, avoiding the need to configure LFS over HTTP. That’s when I discovered git-lfs-transfer: a command-line interface tool that lets you use Git LFS over SSH, eliminating the need for HTTP.
This article will walk you through setting up and using git-lfs-transfer for a seamless Git LFS experience over SSH.
Before diving in, make sure you have the following:
git-lfs-transferThe git-lfs-transfer tool is hosted on GitHub under the repository bk2204/scutiger. It’s easy to install using Rust’s package manager, Cargo. Here’s how:
Open your terminal or command prompt.
Run the following command:
cargo install --git https://github.com/bk2204/scutiger.git scutiger-lfsThis command fetches the scutiger-lfs project and installs the git-lfs-transfer tool on your system.
Verify the installation by typing:
git-lfs-transfer --versionIf the tool is correctly installed, this command will display its version.
To use git-lfs-transfer, you need to set it up on both the client (your machine) and the server (where your Git repository is hosted).
Server Setup
Install git-lfs-transfer: Follow the same installation steps as on the client. Ensure Rust and Cargo are available, and do the steps above.
Configure the server’s PATH:
Ensure that the git-lfs-transfer binary is in the PATH of the SSH user that executes the Git commands. Keep in mind that the environment used for direct command execution over SSH might differ from an interactive shell. For example, if you’re using bash, ensure that the PATH is set in a file like .bashrc or .profile instead of .bash_profile, as the latter is only used for interactive shells. To verify, use a direct SSH command like:
ssh git-user@my-git-server.com which git-lfs-transferThis command should return the path to the git-lfs-transfer binary. If it doesn’t, adjust your environment variables or move the binary to a directory in the PATH.
Verify the setup:
Error: Command Not Found
git-lfs-transfer is installed and in your PATH on both the client and server. Note that binaries installed with cargo install are local to the user who runs the command by default. Therefore, you must either run the installation with the same user under which the Git repository operates or manually copy the binary from the user’s local bin directory to a system-wide bin directory (e.g., /usr/local/bin).Permission Denied
git-lfs-transfer binary.Large File Transfers Not Working
Verify that Git LFS is initialized in your repository. Run:
git lfs install
git lfs track "*.filetype"
git add .gitattributes
git commit -m "Track large files with Git LFS"Ensure the .gitattributes file is pushed to the remote repository.
The git-lfs-transfer tool is a powerful way to enhance your Git LFS setup by enabling SSH-based transfers. By following this guide, you can move away from HTTP dependencies and simplify your workflow while maintaining robust handling of large files. Whether you’re hosting your own Git server or working with a team, this tool is a great addition to your version control toolkit.
Happy coding!
© 2024 Alexander Krivács Schrøder. Some Rights Reserved.
You can also leave comments directly on GitHub, should you not want to authorize the utteranc.es API to post on your behalf.