Using GIT to deploy a website

I followed this excellent http://toroid.org/ams/git-website-howto post to deploy code to my server using the Git post-hooks strategy.

I have a post-update file that looks like this:

GIT_WORK_TREE=/home/rajat/webapps/<project name> git checkout -f 

Each time I push the code to the master branch, it is automatically deployed. Now I want to do this to support multiple branches, so that:

  • git push origin master -----> deploys production code (/ home / rajat / webapps / production)
  • git push origin staging ----> expands the code for staging (/ home / rajat / webapps / staging)
  • git push origin test ----> expands the code for testing (/ home / rajat / webapps / test)

To do this, the post-update hook must figure out which branch has been updated. Is it possible?

+7
git githooks
source share
2 answers

You can write a hook after the update, which determines the name of the branch.
See Inspiration:

  • " Writing a git post-receive hook to work with a specific branch
  • " Find Git branch name in post-update hook "

As an example (all these hooks are based on git rev-parse ):

 #!/bin/bash while read oldrev newrev refname do branch=$(git rev-parse --symbolic --abbrev-ref $refname) if [ "master" == "$branch" ]; then # Do something fi done 
+4
source share

What I usually do is add two bare git repositories in different places on my web server; one for dough, one for production. Both repositories have post-hooks to check in the correct directory. Then I add both as remotes to my (one) local repo.

Using this method, I can direct any branch to my test console or my remote control at any time. Not sure if this is the right way, but it worked for me.

+1
source share

All Articles