Skip to content

Instantly share code, notes, and snippets.

@benfrain
Last active June 8, 2024 20:52
Show Gist options
  • Save benfrain/6897792 to your computer and use it in GitHub Desktop.
Save benfrain/6897792 to your computer and use it in GitHub Desktop.
post-receive hook for multiple branches
#!/bin/bash
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [ "master" == "$branch" ]; then
git --work-tree=./path/under/root/dir/live-site/ checkout -f $branch
echo 'Changes pushed live.'
fi
if [ "dev" == "$branch" ]; then
git --work-tree=./path/under/root/dir/dev-site/ checkout -f $branch
echo 'Changes pushed to dev.'
fi
done
# Taken from: http://blog.ekynoxe.com/2011/10/22/git-post-receive-for-multiple-remote-branches-and-work-trees/
@zigotica
Copy link

@benfrain thanx for the trick!
I improved it by making destination folder dynamic, see here: https://coderwall.com/p/qjmp1g

@nilsriga
Copy link

thank you for the script

@jmoka
Copy link

jmoka commented Jun 8, 2024

I did everything, the commit worked correctly but the files do not appear in the remote repository.
Can you help me?

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