Search code examples
gitlocalremote-server

Git: let remote server pull from local server


I currently have the folowing environment:
- local git server (Linux)
- development PCs (Linux mostly)
- remote server for live application (Linux)

Both servers can be reached from the dev PCs (via ssh), but the dev PCs and local git server are not 'online' (just normal consumer home network, no forwarding or similar stuff).

The local git server has the bare repos and the dev PCs have cloned repos of the local git server.

Now I want to clone the repo from the git server to the remote server. The remote server is the live server of the applicatio. So everytime the application gets an update, the remote server has to pull from the local server again.

As I never had this use case before (remote can't reach the local server to pull) I am at a total loss on how to do this.

Thanks in advance to everyone trying to help :)


Solution

  • If I interpret the original question correctly, the local server is only accessible by the development PCs but not from the remote server.

    That means one possible solution would be to push to the server repository within the local repository (instead of fetching from the local repository within the server repository). You can even push to an empty repository:

    $ git push -u <server-repo> <branch-name>
    

    The option -u is optional and is just used to set the default remote branch for subsequent pushes.

    Because the repository on the remote server are not bare (you need a checkout for the applications), it will refuse pushes to checked-out branches by default.
    There are several options to solve this. One variant is to utilise the push-to-checkout hook which seems to do exactly what you need. Please refer to git help githooks for details. Don't forget to set the configuration receive.denyCurrentBranch accordingly and to ensure that index as well as files are never changed by remote server.