Git LFS client (git-lfs
or git lfs
command) requires a dedicated LFS-content server (not the Git server!) in order to download/upload binary files. There will be an issue if you try to use a mirror of a Git repo with LFS-enabled: git-lfs#1338. This Git LFS server implementation solves that problem.
There are other implementations that you can look for if you're not working with Git mirrors.
-
Maintained by: Khoa
-
Supported architectures:
amd64
,arm64
-
Documentation: git-lfs-server Wiki.
-
Where to get help: git-lfs-server Discussions
There are two important reasons to set up a Git server for mirroring with LFS-enabled:
- To save bandwidth on the connection to the remote server, especially if the repositories are big.
- Team members don't have access to the remote server, but your Git server can.
- Only download operation is supported. You cannot upload binary files.
- LFS contents in the mirror are not fetched automatically by this tool.
For the sake of simplicity, I have created a Docker Hub repository with the images ready to use. Assumed that you have the same problem as in git-lfs#1338 (There's a picture in it if you like graphical presentation). Although, for a smoothly experience, I would add some more details:
- Mirrors will be accessible via SSH, i.e., you can do
git clone git@GIT_SERVER:MIRROR_REPO.git
, orgit clone ssh://git@GIT_SERVER:PORT/MIRROR_REPO.git
- Self-signed certificate: we need a
.key
file, a.crt
file, a.pem
file. Follow this guide to create one. - You will need some automation to fetch latest Git references and LFS contents from the far repositories, in case the far repositories are newer than the mirrors.
- Far remote is LFS-enabled.
- Near remote has Docker installed.
If all requirements are satisfied, let us proceed step-by-step
- Pull the image:
docker pull khoa10/amz-git-mirroring:latest
- There must be a folder named
certificates
with 3 files:git-lfs-server.key
,git-lfs-server.cert
,git-lfs-server.pem
. Create a volume to store the certificate:
$ ls certificates
git-lfs-server.crt git-lfs-server.key git-lfs-server.pem
$ docker volume create --name git-lfs-server-certs
$ docker run --rm -v $PWD:/source -v git-lfs-server-certs:/dest -w /source alpine cp "certificates/git-lfs-server.key" "certificates/git-lfs-server.crt" "certificates/git-lfs-server.pem" /dest
- With your mirrors are located at
$INSERT_YOUR_PATH_HERE
, create the container:
docker run \
--detach \
--env GIT_LFS_SERVER_URL="https://$INSERT_URL_HERE:8443" \
--mount type=bind,src=$INSERT_YOUR_PATH_HERE,dst=/source \
--mount type=volume,src=git-lfs-server-certs,dst=/etc/git-lfs-server/certificates \
-p 8443:8443 \
-p 2022:22 \
khoa10/amz-git-mirroring
Now, your Git server is available at ssh://git@<NEAR_REMOTE>:2022
and the LFS server is available at https://<NEAR_REMOTE>:8443
.
Because we're using self-signed certificate, Git client must either ignore TLS verification or trust the certificate you created.
To ignore TLS verification:
git config --global http.https://<NEAR_REMOTE>:8443.sslverify false
For better experience, client should configure to download from near and push to far:
git config --global url.ssh://git@<NEAR_REMOTE>:2022.insteadOf ssh://git@<FAR_REMOTE>
git config --global url.ssh://git@<FAR_REMOTE>.pushInsteadOf ssh://git@<NEAR_REMOTE>:2022
MIT license