Skip to content

Instantly share code, notes, and snippets.

@jhofker
Last active August 29, 2015 14:15
Show Gist options
  • Save jhofker/5b397e2eaebf9185477e to your computer and use it in GitHub Desktop.
Save jhofker/5b397e2eaebf9185477e to your computer and use it in GitHub Desktop.
post-receive hook to pull another repo on the server
#!/bin/sh
PUBLIC_WWW=/home/public
GIT_DIR=$PUBLIC_WWW/.git
# Pull the latest from the repo to the public dir.
cd $PUBLIC_WWW
echo Pulling.
git reset HEAD --hard
git pull
echo Setting permissions.
chmod 755 *
exit
@jhofker
Copy link
Author

jhofker commented Feb 22, 2015

In this case, I have a local repo hosted on the same server as the web server.

In my project (a simple web project), gulp build produces a folder, dist, that has my server's git repo added as a remote. So I build my web project, producing the output, and then commit that output and push it to master on the server's repo.

This hook then causes the server to go to my public folder, reset (for good measure), and pull to latest.

Of course, if gulp-scp or gulp-scp2 actually worked, I wouldn't have needed to do any of this.

@jhofker
Copy link
Author

jhofker commented Feb 22, 2015

Resources that were helpful (but share none of the blame if I did something stupid):
Major Ursa
torek on StackOverflow

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