Git

Deploy a Project to Your Server with Git

Posted May 29, 2023

By Kevin Schwickrath1 min read

Overview

I’m building my site with Jekyll to a specific directory D:\websitedeploy. However that’s not my webserver. How should I move my site to the live server? We have many options such as carrier pigeon, rsync, sftp, etc. I’ll use Git.

Server Prep

Create the directory for the git repo.

Terminal window
cd /home/username
mkdir livesite.git
git init --bare livesite.git/

Next we need to setup the “action” git should take once we post an update.

Create a file and edit it (I prefer vi) vi livesite.git/hooks/post-receive. Paste the following in the file.

#!/bin/sh
# Check out the files
git --work-tree=/var/www/html --git-dir=/home/username/livesite.git checkout -f

Make this file executable with chmod +x /home/username/livesite.git/hooks/post-receive

Development PC Setup

Let’s do some basic setup to git. These commands tell git to initialize the directory and to use a specific user for this project.

Terminal window
cd D:\websitedeploy
git config user.name "YourName"
git config user.email "username@youremail.com"
git init

Here we tell git to add all the files and directories for tracking. Then we commit the changes.

Terminal window
git add --all
git commit -m "Created repo"

Now we connect the server and development PC. We’re telling git to bind my master branch to the live remote. Then we push to setup everything.

Terminal window
git remote add live 'ubuntu@workswiththeweb.com:/home/ubuntu/livesite.git'
git push --set-upstream live master
git push

Pushing Updates

Now pushing updates is a simple process.

Build Site

Terminal window
cd D:\buildsite
bundle exec jekyll build

Deploy Site

Terminal window
cd D:\websitedeploy
git add --all
git commit -m "Update message"
git push

Now get to work and push some updates.

This post is licensed under CC BY 4.0 by the author.

Related Posts

Git Basics

Git · May 28, 2023 · 3 min read

For Windows you can grab the installer here: https://git-scm.com/download/win.