Skip to content
Switch branches/tags
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Let me break it down in pieces and explain the parts

if [ $(git diff HEAD@{1} HEAD --name-only | grep -E
'base-requirements|prod-requirements' -c) -ne 0 ]
    $VIRTUAL_ENV/bin/pip install -Ur prod-requirements.txt

Essentially what the above is doing, is doing a git diff, grep'ing to see if my base-requirements or prod-requirements files changed, and if they did, doing a pip install prod-requirements (which includes base-requirements) to ensure that all my dependancies are met/installed.

## if a settings file or a models file change, restart uWSGI
if [ $(git diff HEAD@{1} HEAD --name-only | grep -E
'conf/*.py|web_site/*/' -c) -ne 0 ]
        source venv/bin/activate && fab restart_uwsgi

Like the comment says, I'm checking to see if a settings file (located in web_root/conf/) or if a file changes, I want to restart uWSGI (necessary for these changes to take affect.

The next piece:

 ## if a migration file exists, syncdb and migrate
 if [ $(git diff HEAD@{1} HEAD --name-only | grep -E
 'web_site/*/migrations/*.py' -c) -ne 0 ]
     source venv/bin/activate && fab syncdb && fab migrate_all

You don't need to run a syncdb or a migrate (if you're using South) every time you deploy. So I check to see if a new migration file exists, if so, then I run a syncdb and a migrate.

And last, sadly a "dirty" hack (sort of). By default, nginx uses www-data user/group to serve files and I'm actually managing my server as root (cause real Sys Admins use root! :P)

## if a file changed in web_site/ change owner to www-data:www-data
if [ $(git diff HEAD@{1} HEAD --name-only | grep -E 'web_site/' -c) -ne 0 ]
   source venv/bin/activate && fab change_owner

What the above does, is checks to see if a file changed in the web_root directory, if it did, it changes the owner and group (this ensures that nginx can serve the necessary files).

Git hooks have proven to be a time saver. Taking quite a bit of redundancy out of the process/steps necessary to deploy/manage my django projects.

These of course are written to work with my workflow/habits and may not fit everyone, but my hope is to help those who haven't established a workflow, or to give a starting point for everyone else, and can tweak here/there as necessary to support their workflow/habits.


a place I'm going to stash my git hooks



No releases published


No packages published