Git deploy

Creating Git repository


Connect SSH


Create .git directory outside public_html and create bare repo

mkdir project.git
cd project.git
git --bare init

Create post-receive hook

cd hooks
nano post-receive
chmod +x post-receive

post-receive contents

git --work-tree=/home/username/public_html --git-dir=/home/username/project.git checkout -f


Create repository

cd project
git init

Add remote to local repository

git remote add staging ssh://

Just commit and push

git commit -am "first edit"
git push staging master

Default push to staging

git push --set-upstream staging master

Reset remote

To reset remote and push files again to remote

git --work-tree=/home/username/public_html --git-dir=/home/username/project.git reset --hard


Useful resources