Skip to content

Instantly share code, notes, and snippets.

@AbeEstrada
Created March 29, 2018 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbeEstrada/c753c22295fba479f2c95edbcf303036 to your computer and use it in GitHub Desktop.
Save AbeEstrada/c753c22295fba479f2c95edbcf303036 to your computer and use it in GitHub Desktop.
Git `post-receive` script
#!/bin/bash
BASE=/var/www/domain.com
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
commit=$(git rev-parse --short HEAD)
BRANCH_DIR="$BASE/$branch"
BRANCH_TEMP_DIR="$BASE/$branch.temp"
rm -rf $BRANCH_TEMP_DIR
cp -r $BRANCH_DIR $BRANCH_TEMP_DIR || mkdir -p $BRANCH_TEMP_DIR
cd $BRANCH_TEMP_DIR
git --work-tree=$BRANCH_TEMP_DIR --git-dir=$BASE/repository.git checkout $branch -f
# run your custom commands here
rm -rf $BRANCH_DIR
mv $BRANCH_TEMP_DIR $BRANCH_DIR
echo "$commit" > "$BRANCH_DIR/current"
echo "Done!"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment