Skip to content

Instantly share code, notes, and snippets.

@vcastellm
Created August 31, 2010 11:59
Show Gist options
  • Save vcastellm/558927 to your computer and use it in GitHub Desktop.
Save vcastellm/558927 to your computer and use it in GitHub Desktop.
Git auto update hook for web deployment
echo "Enter an existing repository name:"
read REPONAME
cd /home/git/repositories/$REPONAME.git
echo "Configuring bare git repo..."
git --bare update-server-info
git config core.bare false
git config receive.denycurrentbranch ignore
git config core.worktree /var/www/$REPONAME
mkdir /var/www/$REPONAME
chown git:git /var/www/$REPONAME
echo "Working out the hook"
cat >> hooks/post-receive <<-"EOA"
#!/bin/sh
read oldrev newrev ref
BRANCH=`echo $ref | cut -d / -f 3-`
if [ "$BRANCH" = "staging" ]; then
echo "Deploying $BRANCH..."
git checkout staging -f
chmod -R u+rwX,go+rX `git config core.worktree`
fi
EOA
chmod +x hooks/post-receive
echo "=================================================="
echo "Instructions "
echo "=================================================="
echo "Your repository has been configured to deploy to: "
echo "/var/wwww/$REPONAME"
echo "To deploy push to a remote branch named staging"
echo "=================================================="
@vcastellm
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment