Deploy Existing Website to Bare Git Repo

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.

1. Backup your existing site

cp -r /home/site/public_html /home/site/public_html_backup

2. Create a temporary working Git repo

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"

3. Push the contents into the bare Git repo

git remote add origin /home/site/dev
git push origin master

4. Set up the post-receive deployment hook

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

5. Done!

Now any push to /home/site/dev will automatically deploy the site to /home/site/public_html.