This is a quick tips & tricks post I decided to write after switching my personal website to the Hugo Apero theme by using this excellent guide by Silvia Canelon. In it, she describes how she uses branches to switch from one theme to the other without breaking the initial site. The original idea came from the following Twitter thread by the following Tweet by Garrick Aden-Buie and leverages what is known as “Branch Deploys” on Netlify.
Previously, I used to write my entire blog post, served it locally to make sure it rendered correctly, and published it on the main
branch of my repository. This in turn triggered a build instruction on Netlify which built the site with the new post. While this workflow is fine for simple blogs with a single author, I ended up switching to using branches to compartmentalize individual blog posts, render them on a branch deploy on the web to see the final product and to avoid breaking the main site while experimenting things on branches.
Hence, I switched to the following workflow to write new content:
- Head to the site’s settings on Netlify and activate branch deploys for all branches.
- Create a new branch titled after the blog post I want to write
- Create a new blog post using
blogdown::new_post()
- Write the actual post
- Commit and push the changes on the new branch
And that’s already it!
Back to topNB: I am unsure why but when selecting specific branches of my repository the branch deploys did not work when I pushed changes to GitHub.