Updating Your Eleventy Site from a Template
Published on by Eli Carenza
In this tutorial, we'll go over how to update the site you built using the Eleventy template in our previous guide. We'll cover how to add the latest features and improvements from the template to your site, as well as how to resolve any conflicts that may arise during the update process.
Prerequisites
Before we start, make sure you have the following installed:
- Node.js
- NPM
- Git
- Your IDE of choice
This tutorial assumes you have a basic understanding of Git and the command line. If you're new to Git, you may want to familiarize yourself with the basics before proceeding.
It also assumes you've already created an Eleventy site using the template from our previous guide. You may need to adjust the commands and steps based on your specific setup.
Explanation
When you first created your Eleventy site using the template, you copied the template files to your project directory. This means that your site is now a separate entity from the template, and any changes made to the template will not automatically be reflected in your site.
You can update your site from the template by following these steps:
- Add the template as a remote repository
- Fetch the latest changes from the template
- Merge the changes into your site
- Resolve any conflicts that may arise and test your site before committing the changes
Let's walk through each step in detail.
Step 1: Add the Template as a Remote Repository
To add the template as a remote repository, run the following command in your project directory:
git remote add template
Replace <template-repository-url> with the URL of the template repository. This will add the template as a remote repository named template.
Step 2: Fetch the Latest Changes from the Template
To fetch the latest changes from the template, run the following command:
git fetch template
This will download the latest changes from the template repository to your local machine.
Step 3: Merge the Changes into Your Site
To merge the changes from the template into your site, run the following command:
git merge template/main --allow-unrelated-histories
This will merge the changes from the main branch of the template repository into your site. The --allow-unrelated-histories flag is required because your site and the template have unrelated commit histories. If you tried to merge without this flag, Git would throw an error.
Step 4: Resolve Any Conflicts
During the merge process, Git may encounter conflicts if the changes in the template conflict with changes you've made in your site. Git will mark these conflicts in the affected files, and you'll need to resolve them manually. Be mindful when doing this - slow down and make sure you understand the changes you're making. Once you've resolved all conflicts, make sure to do a test run of your site to ensure everything is working as expected.
npm start
Once you're sure everything looks good and is working as expected, you can commit the changes:
git add .
git commit -m "Merge changes from template"
git push
And that's it! Your site is now updated with the latest features and improvements from the template. This makes it much easier to keep your site up-to-date and take advantage of new features as they're added to the template, instead of having to manually copy them over.