motorscript.com

Using git to push websites to server

Published:
This cheatsheet will push your repo to the app directory inside a user home directory in the remote server.
  • Remote/Server (domain name or IP):
  • User on Server :
  • Project Dir :
  • SSH Port :

SSH into the server

cd
mkdir repo.git app
cd repo.git
git init --bare
git --bare update-server-info
git config core.bare false
git config receive.denycurrentbranch ignore
git config core.worktree /home/user/app/

cat > hooks/post-receive <<EOF
#!/bin/sh
git checkout -f
EOF

chmod +x hooks/post-receive

exit

On the client

git remote add server [email protected]:/home/user/repo.git/
ssh-copy-id [email protected]
git push server --all

You may want to modify your git post-receive hook to run custom commands on the server, like running database migrations, notifying services of new deployments, pushing static files to CDN, etc.