Local Git Deployment
Let’s create a two-tiered system that goes from dev to prod using a post-commit trigger
The Development system is your workstation. git commit will trigger a build and rsync.
The Production system is a web server. Any web server will do as long as you have SSH access and can update a web-root folder.
I use Hugo in this example, but any system that has an output (or build) folder works similarly.
The first thing we need to know is where wee are going, so lets prepare production first.
This server probably uses folders like
/var/www/XXXXX for its web root. Use that or create a new folder and make yourself the owner.
sudo mkdir /var/www/some.site.org
sudo chown -R $USER /var/www/some.site.org
echo "Hello" > /var/www/some.site.org/index.html
Edit your web server’s config to make sure you can view that web page. Also check that
rsync is available from the command line.
Hugo builds static html in a
public directory. To generate the HTML, simply type
We don’t actually want this folder in git and most themes (if you’re using Hugo) already exclude it. Look for a
.gitignore file to and create/add if needed.
# Notice /public is at the top of the git ignore file
Assuming you have some content, let’s add and commit it.
git add --all
git commit -m "Initial Commit"
Note: All of these git commands work because pulling in a theme initialized the directory. If you’re doing something else you’ll need to
The last step is to create a hook that will build and deploy after a commit.
chmod +x .git/hooks/post-commit
rsync --recursive --delete public/ [email protected]:/var/www/some.site.org
This script ensures that the remote directory matches your local directory. When you’re ready to update the remote site:
git add --all
git commit --allow-empty -m "trigger update"
If you mess up the production files, you can just call the hook manually.
bash: line 1: rsync: command not found
Double check that the remote host has rsync.
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.