Staying in Sync: Pulling updates for My Blog Template
/ 3 min read
Table of Contents
Like most people, when I first made this blog, I used GitHub’s “Create from template” feature. It’s a great way to get started, but there isn’t an obvious way to keep your repo in sync with the template - as I found out much later. So, how do I pull in the latest changes?
The theme README points to a StackOverflow answer that outlines the process. Here’s my take on it, using v6.1.1 as an example.
Let’s 🚀
Step 1: Add the template repository as a remote
git remote add template git@github.com:chrismwilliams/astro-theme-cactus.git
Step 2: Fetch the specific tag from the template
git fetch template tag v6.1.1 --no-tags
The --no-tags
flag ensures that only the specified tag is fetched, without pulling all the other tags.
Step 3: Create a new branch to track the template
git checkout -b template-v6.1.1 v6.1.1
Step 4: Rebase the template changes onto master
git checkout mastergit rebase template-v6.1.1
Step 5: Resolve any conflicts
When rebasing, you might encounter conflicts between your changes and the template’s updates. In Visual Studio Code, you have three options:
- Accept Current Change: This means accepting the template’s version (despite the phrasing).
- Accept Incoming Change: This means keeping your own changes that you’re rebasing on top of (again, despite the phrasing).
- Accept Both: This keeps both the template’s changes and your own.
No matter which option you choose, it’s best to review the changes before saving, staging (git add
), and continuing the rebase (git rebase --continue
).
For files you haven’t modified, it’s generally safe to “Accept Current Change” (i.e., the template’s version). For files you have customised, you might wanna carefully review the changes and decide which parts to keep, modify, or remove.
If you encounter conflicts in binary files, like images, you can use the following command to keep the template’s version:
git checkout --theirs public/social-card.png
Step 6: Force push the updated master
git push --force-with-lease origin master
To quote a random Redditor: “With just ‘—force’ you don’t even need to know what you are overwriting. With lease the remote needs to be as it was when you last fetched.”
Why Rebase?
The original answer suggests using git merge
, but I elected to use git rebase
. Why? It keeps my commit history clean and linear.
Merging would create a new “merge commit” every time I pull in changes from the template. With rebasing, my own commits are replayed on top of the template changes, as if I had started my work from the latest version of the template.
It’s not ‘true’ history but I can live with that.
Final Thoughts
To make my life easier, I don’t update the template very often - typically only when it adds a great new feature or fixes a critical bug. This usually happens around once a year. And when it does, I’ve got this handy post as reference.