Yes GIT is not meant for deployment and something more robust like Capistrano is optimal. However, while working on a basic project it will suffice.
Being able to steer clear of FTP is the bare minimum. Version control additionally is just too useful not to use even for small apps.
Steps
With that said this will get you started with a semi-decent workflow:
- Enable SSH
You will need to request this from your service provider. I have found that it is best to do this from the account billing page rather than cPanel. I would imagine that the provider doesn’t want you on this page for very long while requesting a change.
- Create SSH
Generate your key using ssh-keygen if you haven’t already.
cd ~/.ssh
ssh-keygen -t rsa -C "email@domain.com"
pbcopy < ~/.ssh/id_rsa.pub
- Copy the key onto your Server
rsync -av -e "ssh -p 2222" ~/.ssh/id_dsa.pub root@ip.add.ress.here:.ssh/authorized_keys
If you run into any problems here check with your host provider.
- Local Repository
mkdir site && cd $_
git init
cat > index.html
....
git add .
git commit -a
- Add Local Push Deployment
git remote add prod ssh://username@ipaddress:port/~/apps/blog/.git
- Server Repository
mkdir .git && cd $_
git init --bare
- Server Hook
GIT wont automatically checkout your changes when you push. You need to setup a hook so that your content will be updated:
cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=~/apps/blog/public git checkout -f
chmod +x hooks/post-receive
Note that GIT_WORK_TREE points to where the .git is located which includes ‘~’.
- Push to Live
Update your deployment
git push prod +master:refs/heads/master
Subsequent pushes
git push prod