0

I am able to implement push-to-deploy with Git by creating a bare repo on the server, and pushing to that from my dev. Below is my post-receive which handles updating the live site:

#!/bin/sh

echo
echo "*** Checking out branch [post-receive hook]"
echo

git --work-tree=/var/www/myproject checkout -f master

Notice that it checkouts "master" branch this works great in most cases. "master" is the branch I push (e.g. git push staging master when pushing to live to the staging server). However, I sometimes like to push a branch only without merging my changes to master (e.g. git push staging new-register-form). Can I change my post-receive hook script to checkout "the last pushed branch"? Is this possible?

Martyn
  • 4,941
  • 9
  • 40
  • 97

1 Answers1

0

Yes, you can, like this:

#!/bin/bash
while read oldrev newrev refname
do
    branch=$(git rev-parse --symbolic --abbrev-ref $refname)
    git --work-tree=/var/www/myproject checkout -f $branch
done

taken from: here

Community
  • 1
  • 1
mlkmt
  • 237
  • 2
  • 9