Guide: Use Git for deployment

Post cover image

Prepare server

  1. Use SSH to get to webspace: ssh user@webspace.host
  2. Navigate to correct directory: cd myapp/production
  3. Create Git folder: mkdir .git
  4. Navigate to the folder: cd .git
  5. Init bare repository: git init --bare
  6. Create file called "post-receive" in .git/hooks with this content:

#!/bin/sh

The production directory

TARGET="/kunden/homepages/xx/xxx/htdocs/myapp/production/app"

The Git repo

REPO="/kunden/homepages/xx/xxx/htdocs/myapp/production/.git"

Deploy the content to the directory

git --work-tree=$TARGET --git-dir=$REPO checkout -f

Update: It's important that your "post-receive" file has the permission to execute. In my case, I gave the file permission 705.

Prepare local development setup

  1. Project folder has to be a Git repository. If it isn't already, run: git init
  2. Add remote: git remote add deploy ssh://user@webspace.host/kunden/homepages/xx/xxx/htdocs/myapp/production/.git

Upload changes

  1. Commit local changes.
  2. Run this to upload them: git push deploy HEAD