1

I have an existing git environment set up like this:

Diagram of existing git environemnt

In order to deploy my changes to the production server, currently I:

  1. run git commit on the dev copy
  2. run git push to send my changes to project.git, the central repository
  3. ssh into the production server
  4. run git pull on the live copy

I would like to eliminate steps 3 and 4 when pushing the master branch. I have found multiple tutorials (like this one) on using the post-receive hook, but they all seem to assume that the bare repository will live on the production server, like this:

Tutorial environment assumptions

In this scenario the live copy can be updated using post-receive by setting GIT_WORK_TREE to the correct local directory, and then running git checkout -f master.

That's very slick, but it doesn't work with my existing environment. I could always move my central repo from the development server to the production server, but I'm hoping there's some straightforward way to just notify the live copy to do a git pull automagically when the central repository receives a push.

Any suggestions, or should I just bite the bullet and move the central repo to production?

  • 1
    why not just make a hook that runs "ssh server git pull"? – Esben Skov Pedersen Nov 10 '16 at 5:59
  • So basically your productionserver is like a "live copy" of your development server? Isn't that antithetical. – Pieter B Nov 10 '16 at 7:42
  • 1
    @EsbenSkovPedersen Because I had no idea that you could use ssh user@MachineB 'bash -s' < local_script.sh to run a command remotely. Now I do. Log that as an answer and I'll accept it. – Will Martin Nov 10 '16 at 8:20
  • 1
    @PieterB I don't see how those two are antithetical. This particular project consists of 12 HTML files and about 8,000 lines of plain text configuration files. We're just using git to keep track of who touched the config file last, and so we can roll back changes if somebody pushes a bad config for some reason. – Will Martin Nov 10 '16 at 8:25
2

ssh takes parameters of the command it should run so you can just create a hook that will run git pull on the remote server.

ssh user@MachineB 'bash -s' < local_script.sh

or

ssh user@machineB remote_cmd
  • This worked perfectly. I can now push the master branch to the central repo and have the production copy auto-pull it. Thanks. – Will Martin Nov 10 '16 at 17:08
-1

The git server itself knows nothing about who is interested in commits to it, so can't do this.
Of course it would be possible to have some sort of external process that monitors the server for changes to the codebase to which people and processes can subscribe. Which is if I'm not mistaken how the notification systems on github and bitbucket work.
But the work would have to be all done by that external process, probably through periodically checking the commit messages to the server or something like that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.