$ cat ~/.ssh/id_rsa.pub | ssh -i ~/.ssh/your_pemfile.pem ubuntu@your_ip_addr "cat>> .ssh/authorized_keys"
$ cd ~
$ mkdir ProjectDir.git && cd ProjectDir.git
$ git init --bare
$ nano hooks/post-receive
echo '--- --- --- --- --- --- --- --- --- --- ---'
echo 'Deploying site...'
echo '--- --- --- --- --- --- --- --- --- --- ---'
if ! [ -t 0 ]; then
read -a ref
fi
IFS='/' read -ra REF <<< "${ref[2]}"
branch="${REF[2]}"
# Master Branch
if [ "master" == "$branch" ]; then
echo "Master Post Receive"
readonly HTTP_HOST=example.com
readonly REMOTE_TARGET=/var/www/webdisk/${HTTP_HOST}/htdocs/
GIT_WORK_TREE=${REMOTE_TARGET}
export GIT_WORK_TREE
git checkout -f
echo "End Post Receive"
fi
echo '--- --- --- --- --- --- --- --- --- --- ---'
$ chmod +x hooks/post-receive
$ git init
$ git remote add ec2 ssh://ubuntu@your_ip_addr/home/ubuntu/ProjectDir.git
$ git push ec2 +master:refs/heads/master
note: only have to use “+master:refs/heads/master for 1st push
$ git push ec2 master
[remote "all"]
url = https://github.com/YourGitAccount/ProjectDir.git
url = ssh://ubuntu@your_ip_addr/home/ubuntu/projects/ProjectDir.git
$ git push all master