This guide will help you take an existing site in /home/site/public_html
and push it into a bare Git repo at /home/site/dev
, which deploys to the site using a post-receive
hook.
cp -r /home/site/public_html /home/site/public_html_backup
cd /home/site
mkdir temp-repo
cd temp-repo
git init
cp -r ../public_html/* . 2>/dev/null
git add .
git commit -m "Initial commit from existing public_html content"
git remote add origin /home/site/dev
git push origin master
cat > /home/site/dev/hooks/post-receive << 'EOF'
#!/bin/bash
GIT_WORK_TREE=/home/site/public_html git checkout -f
EOF
chmod +x /home/site/dev/hooks/post-receive
Now any push to /home/site/dev
will automatically deploy the site to /home/site/public_html
.