This guide outlines configuring a remote deployment setup using Git over SSH with a bare repository and post-receive hook. Ideal for streamlined deployments with minimal operational overhead.
mkdir -p /home/site/dev cd /home/site/dev git init --bare
mkdir -p /home/site/public_html chown -R youruser:www-data /home/site/public_html
cd /home/site/dev/hooks nano post-receive
Save to post-receive:
#!/bin/bash GIT_WORK_TREE=/home/site/public_html git checkout -f
Add permission with shell command:
chmod +x post-receive
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Save it to C:\Users\YourName\.ssh\id_rsa
cat ~/.ssh/id_rsa.pub | ssh youruser@yourserver "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Edit C:\Users\YourName\.ssh\config
:
Host yourproject HostName yourdomain.com User youruser Port 2222 IdentityFile C:\Users\YourName\.ssh\id_rsa
git init git remote add origin yourproject:/home/site/dev git add . git commit -m "Initial commit" git push origin master
To clone your repo later:
git clone ssh://user@domain:port/home/site/dev
Create a file named deploy.bat
:
@echo off echo Deploying to yourproject... git push origin master pause