0

I need to read-only mirror some Git repositories in my local network due to rather slow internet speed. Target would be to update these repositories with crontab just before office hours, so local mirrors would have fresh content at the beginning of the working day.

Currently, I have a local network server, let say name "git.localnetwork", running Ubuntu 22.04. On this, I have directory structure:

/var/www/html/git-mirror/<mirrored git sites>

For example:

/var/www/html/git-mirror/source.codeaurora.org/external/imx/linux-imx.git

On each mirrored repository, I have performed following steps to create the mirror, above given as example:

me@git:/var/www/html/git-mirror$ mkdir -p source.codeaurora.org/external/imx
me@git:<path>$ cd source.codeaurora.org/external/imx
me@git:<path>$ git clone --mirror git git://source.codeaurora.org/external/imx/linux-imx.git
me@git:<path>$ cd linux-imx.git
me@git:<local_mirror_repo_dir>$ git lfs fetch -all

As I understand, these steps are needed in order to create mirror some git repository along with its LFS objects.

Now, to the question: What is the proper way to update these mirrors so, that after command execution, they are again 1:1 snapshot of the remote repository, along with LFS objects? Following have been suggested in various StackOverflow answers, but my understanding of Git is not enough to find out, what of these would be the proper one, and whether they will also update LFS objects.

me@git:<local_mirror_repo_dir>$ git pull
me@git:<local_mirror_repo_dir>$ git fetch
me@git:<local_mirror_repo_dir>$ git fetch --prune 
me@git:<local_mirror_repo_dir>$ git remote update
me@git:<local_mirror_repo_dir>$ git remote update --prune

There is no need or reason to push any local changes to remote repository, as these are read-only repositories.

torek
  • 448,244
  • 59
  • 642
  • 775
Kalle
  • 101
  • 1
  • 10
  • 1
    When using Git-LFS, the large files are *not in Git*. All the Git repository has is information used by the (separate) LFS programs to obtain files from an LFS server. So making a *Git* mirror is fine; it mirrors the *Git* data, including the information needed to reach the LFS server. It does not mirror the large files, because they're on the LFS server. If you need them mirrored to a different LFS server, you'll need some completely separate, non-Git operation for that. – torek Oct 05 '22 at 16:56
  • 1
    Meanwhile, I updated your tags so that someone more familiar with the LFS side of things can answer questions about the LFS servers. Note that [tag:lfs] translates to Linux From Scratch, not Git-LFS. – torek Oct 05 '22 at 16:58
  • @torek If the mirroring is performed as I explained, i.e. LFS objects are fetched into the directory, are those still served properly to the client, which connects to this mirror? – Kalle Oct 06 '22 at 11:11
  • 1
    Since *Git* is unaware of the LFS objects, *Git* doesn't copy them around like this. It's the LFS-server(s) that hold the "source of truth" copy (or copies). Can the new mirror reach the old LFS server? (I don't know, can it?) Will the old server deliver to the new mirror or clones made from the new mirror? (I don't know: will it?) No *Git* command can do anything to the LFS server unless it's tricked by Git-LFS into running something extra. `git checkout`, `git add`, and similar are tricked via the smudge and clean filters, but most other Git commands aren't. – torek Oct 06 '22 at 16:45
  • 1
    Note that `git lfs ` is not a *Git* command, it's an LFS command. (Git has a general extension mechanism where if you run `git xyzzy` and Git has never heard of `xyzzy`, Git tries to find a program named `git-xyzzy`, on the assumption that you've installed some extension of your own. If it does find a `git-xyzzy` it runs that.) – torek Oct 06 '22 at 16:49

1 Answers1

0

LFS has a couple of commands to fetch all content and push it.

git lfs fetch --all source

...

git lfs push --all target
jessehouwing
  • 106,458
  • 22
  • 256
  • 341