It's best to test locally. You can iterate faster that way. Fast iteration is extremely important. The time you spend on git pushes and remote connection latency add up, and will cost you more than setting up a complete local dev env.
Either way, at some point or another you will need to test your changes remotely as well. You can do that with a post-receive hook on your test server. Here's one way to do it.
On the test server:
- Create a bare clone of your repo. Let's call this repo "testing".
- Clone from testing, and set it up as the remote website you test in your browser
- Create a post-receive hook in the testing repo that will update the website from the newly received branch
The post receive hook script:
#!/bin/sh
while read oldrev newrev refname
do
upgrade_sh=./upgrade.sh
if test -e $upgrade_sh; then
upgrade_sh=$(readlink $upgrade_sh || echo $upgrade_sh)
echo calling upgrade script: $upgrade_sh
$upgrade_sh $refname
else
echo NOT calling non-existent upgrade script: $upgrade_sh
fi
done
Put it in .git/hooks
of testing, and make it executable.
I usually keep the upgrade.sh
script inside my project under version control, and create a symlink to it from the hooks
directory. The upgrade.sh
main job of the upgrade script is to reset the deployment directory to the branch that you pushed:
#!/bin/sh -e
unset GIT_DIR
git checkout -f $1
In most cases you want to do more than this, for example on my Django websites I need to regenerate static content and signal restart to Apache.
I hope this will help you get started.