Angelo
Angelo

Reputation: 427

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.

Upvotes: 2

Views: 158

Answers (2)

cypheon
cypheon

Reputation: 1023

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.

Upvotes: 1

René Höhle
René Höhle

Reputation: 27325

I use for such deployment tasks Jenkins. Its a very good system to run tasks and check your code before deployment.

https://jenkins-ci.org

Another solution is Ansible to run code on your server (on all server) the combination with Jenkins is very good.

http://www.ansible.com/home

Or you can write a simple shell script with contains all your commands and you call it in your hook. But i prefer a deployment system to run some tasks and check my code before it goes to production.

Upvotes: 1

Related Questions