Skip to content

Instantly share code, notes, and snippets.

@chusri
Forked from noelboss/git-deployment.md
Created July 22, 2019 07:34
Show Gist options
  • Save chusri/bca74232addefbe966b9d486525ca56f to your computer and use it in GitHub Desktop.
Save chusri/bca74232addefbe966b9d486525ca56f to your computer and use it in GitHub Desktop.
Simple automated GIT Deployment using Hooks

Simple automated GIT Deployment using GIT Hooks

Here are the simple steps needed to create a deployment from your lokal GIT repository to a server based on this in-depth tutorial.

How it works

You are developing in a working-copy on your local machine, lets say on the master branch. Most of the time, people would push code to a remote server like github.com or gitlab.com and pull or export it to a production server. Or you use a service like my Deepl.io to act upon a Web-Hook that's triggered that service.

But here, we add a "bare" git repository that we create on the production server and pusblish our branch (f.e. master) directly to that server. This repository acts upon the push event using a 'git-hook' to move the files into a deployment directory on your server. No need for a midle man.

This creates a scenario where there is no middle man, high security with encrypted communication (using ssh keys, only authorized people get access to the server) and high flexibility tue to the use of .sh scripts for the deployment.

Prerequisit

  1. Have a local working-working copy ready
  2. Have SSH Access to your server
  3. Optonaly configure your server for access with ssh-key (google it)

Todos

  1. Create a folder to deploy to on production server (i.e. your httpds folder)
  2. Add a bare repository on the productions server
  3. Add the post-receive hook script to the bare repository (and make it executable)
  4. Add the remote-repository resided on the production server to your local repository
  5. Push to the production server, relax.

1. Have a local working-working copy ready

Nuf said. I asume we are working on master – but you could work on any branch.

2. Create a folder to deploy to

ssh into your prodctionserver:

$ ssh [email protected] $ mkdir deploy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment