Skip to content

Instantly share code, notes, and snippets.

@williamespindola
Created August 19, 2013 17:17
Show Gist options
  • Save williamespindola/6271617 to your computer and use it in GitHub Desktop.
Save williamespindola/6271617 to your computer and use it in GitHub Desktop.
hook post-receive file to checkout of branch master when deploy from my localhost to the server
#!/bin/bash
#
docroot="/my/path/to/root/of/my/project/"
while read oldrev rewrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [ "master" == "$branch" ]; then
git --work-tree=$docroot checkout -f $branch
fi
done
@williamespindola
Copy link
Author

To configure it, log-in on the server via ssh
Create git bare files on my root or public_html.

$ mkdir app.git && cd app.git
$ git init --bare

Create or rename file in app.git/hook/post-receive. and put above.
After this, change permissions of post-receive file:

$ chmod +x hooks/post-receive

Create remote.

$ git remote add deploy ssh://login@project.com.br/~/path-to-root-or-public_html/app.git

and push..

$ git push deploy master

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