Guide: Use Git for deployment

Post cover image

Prepare server

  1. Use SSH to get to webspace: ssh
  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:


The production directory


The Git repo


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://

Upload changes

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