使用GIT部署网站 [英] Using GIT to deploy website
问题描述
我遵循了这篇优秀的文章 http://toroid.org/ams/git-website
我有一个更新后的文件,它看起来像像这样:
GIT_WORK_TREE = / home / rajat / webapps /< project name> git checkout -f
每次我将代码推送到 master 分支时,自动部署。我现在想要做的是让这个支持多个分支,所以:
$ b $ ol <$> b $ b
为此,更新后的钩子需要了解哪个分支得到了更新。这是可能的吗?
可以编写一个检测分支名称的更新后钩子。 $ b见灵感:
一个例子(所有这些钩子都基于 git rev-parse
):
#!/ bin / bash
while oldrev newrev refname
do
branch = $(git rev-parse --symbolic --abbrev-ref $ refname)
if [master==$ branch];然后
#做某事
fi
完成
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:
- git push origin master -----> deploys code to production (/home/rajat/webapps/production)
- git push origin staging ----> deploys code to staging (/home/rajat/webapps/staging)
- 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 ?
It is possible to write a post-update hook which detect the branch name.
See for inspiration:
- "Writing a
git post-receive
hook to deal with a specific branch" - "Find Git branch name in post-update hook"
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
这篇关于使用GIT部署网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!