gitclonegit-clonegit-fetch

sharing a git repository to a machine that does not have internet access from one that has


I have this setup

machineA -> remote server with a repo.git initialized with --bare

machineB -> client that can access to internet and clone repo.git, so it locally will have repo

machineC -> connected in LAN with machineB and no internet access

The goal is to make machineC work (in read-only mode) with the machineB repo as if it was the remote one. Because of this, machineB is periodically doing a git fetch from the remote server

I am sharing the local machineB repo via SMB and I am able to clone it from machineC.

The issue is that I am just be able to get the master branch or only the local branches I have on machineB, not all the branches present on machineA.

Is there any command to fetch locally everything or to transform the repo into a .git one?

Cheers


Solution

  • In machineB, make a mirror clone from machineA

    git clone --mirror /url/to/machineA/repository
    

    In machineC, clone from the mirror repository in machineB

    git clone /url/to/machineB/repository
    

    When the machineC repository needs the latest data from machineA, first update the mirror repository in machineB

    git remote update
    

    and then update the repository in machineC

    git fetch
    

    The issue is that I am just be able to get the master branch or only the local branches I have on machineB, not all the branches present on machineA.

    In your current situation, you can still fetch all the branches and tags in the machineC repository by

    git fetch origin refs/remotes/origin/*:refs/remotes/origin/* refs/tags/*:refs/tags/*
    

    But it's unnatural and confusing. By turning the machineB repository from a non-bare repository to a mirror repository, we can use familiar commands in the machineC repository.