Using GIT to deploy website
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/bashwhile read oldrev newrev refnamedo branch=$(git rev-parse --symbolic --abbrev-ref $refname) if [ "master" == "$branch" ]; then # Do something fidone
What I usually do is add two bare git repos in different locations on my web server; one for test, one for production. Both repos have post-hooks to checkout to the correct directory. Then I add both as remotes on my (single) local repo.
Using this method I can push any branch to my test remote or my production remote at any time. Not sure if this is the right way but it's worked well for me.