Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

githooks - Using GIT to deploy website

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

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

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

Everytime I push code to master branch, it gets auto deployed. What I want to do now is to make this support multiple branches, so that:

  1. git push origin master -----> deploys code to production (/home/rajat/webapps/production)
  2. git push origin staging ----> deploys code to staging (/home/rajat/webapps/staging)
  3. git push origin test ----> deploys code to test (/home/rajat/webapps/test)

For this, the post-update hook needs to understand which branch got updated. Is this possible ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It is possible to write a post-update hook which detect the branch name.
See for inspiration:

As an example (all those 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...