How can I modify git post-update hook to only activate on one (master) branch?
I set up a bare repo on my web host and cloned a repo off of it that will be updated whenever changes are pushed to the bare repo. The cloned repo on the web host is essentially "production," it sits in the public_html directory. I followed the instructions on this site pretty closely:
http://www.ibm.com/developerworks/web/library/wa-git/
It instructed me to make a 'post-update' hook in the bare repo:
#!/bin/bash
WEB_DIR="<web_dir>"
export GIT_DIR="$WEB_DIR/.git"
pushd $WEB_DIR > /dev/nu开发者_运维知识库ll
git pull
popd > /dev/null
This is a great VCS solution if I'm only working on the master branch.
When I'm at location A, I want to clone the bare repo, start working on branch "newstuff", commit the changes, and then push it to the bare repo so that if I go to location B, I can clone the bare repo and have access to "newstuff." But I don't want "production" to be updated via the post-update script.
Is there a way I can modify my post-update script to only do its thing when an update is made on the master branch?
The refs that were updated are passed to the hook as arguments. This means that you can check for master using case
:
case " $* " in
*' refs/heads/master '*)
# Do stuff
;;
esac
By the way, git pull
on the server will only fetch the other branches, but won't modify your working directory if master was not updated, so this isn't really necessary (except when you're concerned about performance perhaps).
Also see the official documentation about the hook: http://schacon.github.com/git/githooks.html#post-update
精彩评论