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.
cd /home/usernamemkdir livesite.gitgit 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 filesgit --work-tree=/var/www/html --git-dir=/home/username/livesite.git checkout -fMake 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.
cd D:\websitedeploygit config user.name "YourName"git config user.email "username@youremail.com"git initHere we tell git to add all the files and directories for tracking. Then we commit the changes.
git add --allgit 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.
git remote add live 'ubuntu@workswiththeweb.com:/home/ubuntu/livesite.git'git push --set-upstream live mastergit pushPushing Updates
Now pushing updates is a simple process.
Build Site
cd D:\buildsitebundle exec jekyll buildDeploy Site
cd D:\websitedeploygit add --allgit commit -m "Update message"git pushNow get to work and push some updates.
This post is licensed under CC BY 4.0 by the author.
Related Posts
Git Basics
For Windows you can grab the installer here: https://git-scm.com/download/win.