Search code examples
gitgithububuntu-server

Deploying to web server & github with one command


I have a web server with a bare repo in the folder /var/git/mysite.com.git. My hooks/post-receive looks like this:

#!/bin/sh GIT_WORK_TREE=/var/www/mysite.com/public_html git checkout -f

I run git push live master(where live is the name of my remote on the production server) and the post-receive executes properly and puts the files where they need to be in the web root. I then have to run git push origin master to push a copy to my github(for backup/review). I may do these in the opposite order as it accomplishes the same thing.

Is there anyway to accomplish both of these steps with one command? It would seem like I could just put the second git push command in the post-receive or somewhere else(on Github?) push the repo to both remote locations but I have not found a solution to this yet.


Solution

  • You can add the following lines to your ~/.gitconfig file, to achieve this with an alias:

    [alias]
      push-live = !git push live master && git push origin master
    

    Then you can run git push-live, to push to both remotes.