How to Publish a Jekyll Site with Git

In this article, we're going to show one way (among many) to automate the publishing process for a Jekyll site.     This is an advanced article and requires referencing of other information.  Where appropriate, links to supporting material have been provided. </p> <p>    Before proceeding with this article, it is highly recommended that you familiarize yourself with <a href="/support/website/git/">Git</a>.   Git is a popular version control system we will use to publish our site. </p> <p>   But, if you already know Git well, and you're ready to proceed, we will learn <strong>how to publish a Jekyll site with Git</strong>. </p> <a name="part1"></a> <h2>Make Sure Git is Installed</h2> <p>     In order to use the automation process we're going to show here, you must have Git <a href="/support/website/git/how-to-install-git/">installed</a> on your computer (local) and your server (remote). </p> <a name="part2"></a> <h2>Initialize Git in Your Jekyll Directory</h2> <p>   First, we will need to go into our Jekyll site directory via command line and initiate a Git repository. </p> <ol class="article_list"> <li>Open your terminal application</li> <li>Use the <span class="cli">cd</span> command to change into the Jekyll site directory on your computer</li> <li>Run the Git initialization command here<br/><pre class="cli">chris@computer$ <span style="color:green;">git init</span></pre></li> </ol> <p>     You have now initialized a Git repository in your local site.   You can now use Git to version control your site and push it to your server.    Keep reading to find out how to accomplish this. </p> <a name="part3"></a> <h2>Add a Remote Repository to Your Server</h2> <p>  In this stage of the process, we're going to create a remote Git repository on our server.  This remote repository will server many purposes.   It will be a place to store your site information remotely, and thus can be used as backup.     It will also be able to "check out" or publish the site files. </p> <p>     Here we will reference our full guide on <a href="/support/website/git/using-git-to-publish-files/">publishing files to your server with Git</a>.   However, in this instance, use this as the post-receive hook:<br/><pre class="code_block"> #!/bin/sh git --work-tree=/home/userna5 --git-dir=/home/userna5/production.git checkout HEAD -- /public_html</pre> </p> <p>  As in the reference guide, make sure to substitute <em>userna5</em> with your correct cPanel username. </p> <a name="part4"></a> <h2>Change Your Site's Base Directory (Important)</h2> <p>     You may remember in the article about <a href="/support/website/jekyll/how-to-customize-your-jekyll-site/">customizing Jekyll</a>, we learned that you can change the "build" directory for your site.  This is know as the base directory.     It's the directory from which the site is served. </p> <p>  Your InMotion Hosting server (with cPanel) has already chosen <code>public_html</code> as the root directory for serving your site.  You could change this behavior, but it would be easier to work with it instead.     In order to do this you will just need to create a folder called <code>public_html</code> in your site directory.    Then, change the base directory for your site to that <code>public_html</code> folder.   Now, when you run the <span class="cli">jekyll build</span> command, your site files will be built in the <code>public_html</code> directory. </p> <a name="part5"></a> <h2>Completing the Process</h2> <p>  Now you have a local and remote repository for your site.   Using the <span class="cli">jekyll build</span> command, you can now build your site to the <code>public_html</code> directory.  Then, you can use Git to push the site to the remote repository and simultaneoulsy checkout the site files to the appropriate folder. 
Christopher Maiorana Content Writer II

Christopher Maiorana joined the InMotion community team in 2015 and regularly dispenses tips and tricks in the Support Center, Community Q&A, and the InMotion Hosting Blog.

More Articles by Christopher

Was this article helpful? Join the conversation!

Leap into Savings
Leap Ahead with Limited Time Deals