Git LFS – Synology NAS

This post demonstrate how to make an Git LFS for each repository, though it’s possible to use as a shared LFS for all repositories. For the last case using lfs-folderstore would be more applicable.

Requirements

  • Install Git Server package in Synology.
  • Assume SSH access to the Synology.
  • Client side:
    • Install git-lfs-rsync-agent or lfs-folderstore.
    • (Optional) Install GO Programming Language to build the source.

Install ‘git-lfs-rsync-agent’ or ‘lfs-folderstore’

MacOSX

# Install GO using port. Brew should be fine as well.
port install go

# Build source.
cd git-lfs-rsync-agent
go build main.go

# Rename and install to an easy access directory.
mv main ~/opt/local/bin/git-lfs-rsync

Setup Repository & LFS

Synology NAS

# On Synology: create a repository.
mkdir RemoteRepo
cd RemoteRepo

# Initialise Alternative 1:
git init --bare

# Initialise Alternative 2:
# (Optional) Make as a working repository.
git init
git config --local receive.denyCurrentBranch updateInstead

# Make LFS directory (RemoteRepo/.git/lfs).
mkdir .git/lfs

# (Optional)
# When pushing a branch to the origin repo, git-lfs tries to contact the
# inexistent git-lfs server. If this happens, make sure the locks
# verify feature is disabled:
git config --replace-all lfs.locksverify false

Client

# Clone the repository on the client.
git clone ssh://[email protected]:port/RemoteRepo LocalRepo
cd LocalRepo

# Install LFS.
git fls install

.... add files.

# Track files and directories to be in FLS.
git lfs track "bigfile.bin"
git lfs track "*.mp4"
git lfs track "dir/**"

.... commit changes.

# Setup git-lfs-rsync.
git config --replace-all lfs.concurrenttransfers 8
git config --replace-all lfs.standalonetransferagent rsync

# ~/opt/local/bin/git-lfs-rsync
git config --replace-all lfs.customtransfer.rsync.path git-lfs-rsync
git config --replace-all lfs.customtransfer.rsync.concurrent true

# ssh://[email protected]:port/RemoteRepo/.git/lfs
git config --replace-all lfs.customtransfer.rsync.args RemoteRepo

# Push to server.
git push origin master

Cloning Existing Repository

Cloning the existing repository would be the normal process, in order to fetch LFS contents, it’s necessary to configure where the LFS content is located.

# Clone repository as normal.
git clone ssh://[email protected]:port/RemoteRepo LocalRepo

# Configure LFS location.
cd LocalRepo

git config --replace-all lfs.customtransfer.rsync.path git-lfs-rsync
git config --replace-all lfs.customtransfer.rsync.concurrent true

# ssh://[email protected]:port/RemoteRepo/.git/lfs
git config --replace-all lfs.customtransfer.rsync.args RemoteRepo

# Hard checkout.
git reset --hard master

Relocate Existing FLS Repository

Assume the new repository or host has git-lfs, otherwise setup as describe as above.

# Clone the repository (describe as above).
  
# Set up named remotes for 'new repository'.
git remote add newrepo ssh://[email protected]:port/NewRemoteRepo
git remote add oldrepo ssh://[email protected]:port/RemoteRepo

# Fetch all Git LFS content from 'old repository'.
git lfs fetch --all oldrepo
 
# Push all Git and Git LFS content to 'new repository'.
git push --mirror newrepo
git lfs push --all newrepo

References