Post

Deploy a Project to Your Server with Git

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.

1
2
3
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.

1
2
3
4
#!/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.

1
2
3
4
cd D:\websitedeploy
git config user.name "YourName"
git config user.email "[email protected]"
git init

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

1
2
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.

1
2
3
git remote add live '[email protected]:/home/ubuntu/livesite.git'
git push --set-upstream live master
git push

Pushing Updates

Now pushing updates is a simple process.

Build Site

1
2
cd D:\buildsite
bundle exec jekyll build

Deploy Site

1
2
3
4
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.

Comments powered by Disqus.

© Kevin Schwickrath. Some rights reserved.

Using the Chirpy theme for Jekyll.