0

I have my development machine where I develop the code, my server machine where I host it and my central git repo machine.

From my development machine, how can I push and get both the central repo and the server machine updated automatically?

Should I push to server and have a server post action to push to server and if so, how do I do this?

Andrew Aylett
  • 39,182
  • 5
  • 68
  • 95
user391986
  • 29,536
  • 39
  • 126
  • 205
  • If the question is how to push a ref to multiple remotes at once, [this SO answer](http://stackoverflow.com/a/3195446/215168) should cover it. – Abe Voelker May 18 '12 at 19:38

1 Answers1

1

Since there are no built in "post-push" hooks for git, an easy way to accomplish that would be to designate a certain branch as 'production' branch (typically master branch is used for that purpose) and then create a deployment script (say git-deploy.sh) which would pull the most recent code from master branch on your server. Then, you could create a git alias like this:

git config alias.xpush \!git push origin master && git-deploy.sh

which you can then run it by using

git xpush
BluesRockAddict
  • 15,525
  • 3
  • 37
  • 35
  • Thanks that sounds good! Question though if my development machine is windows, besides shooting myself in the foot how do I change that command? I'm using git bash on windows so can it still execute .sh script? – user391986 May 18 '12 at 19:33
  • On Windows, you would just need to create a `.bat/.cmd` script that does the deployment (basically `git pull origin master`) on remote server using `at.exe`, `psexec.exe` or powershell. Git commands would stay the same except the actual name of your script file. – BluesRockAddict May 18 '12 at 19:55
  • git bash *is* a bash, so you can use bash scripts there. – ThiefMaster May 18 '12 at 21:27