Skip to content

Instantly share code, notes, and snippets.

@voxpelli
Forked from perifer/post-receive
Created October 22, 2010 12:24
Show Gist options
  • Save voxpelli/640444 to your computer and use it in GitHub Desktop.
Save voxpelli/640444 to your computer and use it in GitHub Desktop.

Use the post-receive in a repo on eg. your testing or production server. Create a git-repo on the server for the code you want to run there and add it as a remote to your local checkout of your project repo. Whenever you want to deploy you push to the git repo on the server and with the below script as the post-receive hook on the project the server will automatically update with the new code.

Originally described in a now probably slightly outdated blog post: http://blogs.goodold.se/tech/2009/06/26/git-workflow-going-live/

To use this hook the git repository on the server should have another branch than its master branch checked out. The git repo on the server can be an entirely new one and doesn't have to be a checkout of your project repo. Creating an entirely new repo involves some fiddling with temporary commits and force pushing though - nothing complicated, but perhaps not something that everyone is used to be doing.

#!/bin/sh
repo="`pwd`"
export GIT_DIR="$repo"
wd="`dirname $repo`"
echo "$repo"
echo "$wd"
cd "$wd"
git rebase master
git submodule init
git submodule update
cd "$repo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment