Skip to content

Instantly share code, notes, and snippets.

@jrlangford
jrlangford / post-receive
Created August 4, 2016 16:21
Git production repo post-receive hook to automatically deploy code.
#!/bin/bash
while read oldrev newrev ref
do
if [[ $ref =~ .*/master$ ]];
then
echo "Master ref received, deploying master branch to production"
git --work-tree=<Target dir from which static content will be served> --git-dir=<source bare repo dir> checkout -f && \
echo "Success, master branch deployed!!" || \
echo "Error while deploying master branch"
fi
@jrlangford
jrlangford / pre-receive
Created August 4, 2016 17:11
Git hook to reject pushes from branches which are not master
#!/bin/bash
while read oldrev newrev ref
do
if ! [[ $ref =~ .*/master$ ]];
then
echo "Error: Only \"master\" branch is accepted by this repository"
exit 1
fi
done