Git deploy

Creating Git repository

Remote

Connect SSH

ssh username@mydomain.com

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

#!/bin/sh
git --work-tree=/home/username/public_html --git-dir=/home/username/project.git checkout -f

Local

Create repository

cd project
git init

Add remote to local repository

git remote add staging ssh://username@mydomain.com:/home/username/project.git

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

#!/bin/sh
git --work-tree=/home/username/public_html --git-dir=/home/username/project.git reset --hard

Sources

Useful resources

Advertisements