DEV Community

Enda
Enda

Posted on

How to change the theme in your Jekyll application

Originally posted at https://endaphelan.me/technology/programming/changing-theme-in-jekyll-application.

Follow these steps and you will be able to change the theme in your Jekyll application.

Create a new orphan branch and ensure it is empty.

git checkout --orphan newtheme
git rm -rf .
git clean -dfx

Now let's add the theme's repository as an upstream remote and pull the files into our branch. I am using Moon theme by Taylan Tatlı.

git remote add upstream https://github.com/TaylanTatli/Moon.git
git fetch upstream
git pull upstream master

Install Gem dependencies and run your application to see if the previous steps were successful.

bundle install
jekyll serve

All okay so far? Good. Now it's time to merge your blog posts, configuration and other custom files.

This will bring in your posts from master:

git checkout master -- _posts

You can safely merge these files and folders:

  • README.md and other custom Markdown files.
  • _posts directory.
  • _drafts directory.
  • CNAME file.
  • Favicon files.
  • Other custom files and directories such as pictures.

Some old files will conflict with ones from your new theme. The safest thing to do here is to copy the file to a new name and merge it manually.

git show master:_config.yml > _config.yml.old

Accidentally overwritten a theme file? No problem:

git checkout upstream/master -- index.md

I recommend manually merging these files:

  • _config.yml
  • Gemfile

Now replace master with the newtheme branch:

git checkout newtheme
git merge -s ours master --allow-unrelated-histories
git checkout master
git merge

Run the application again to see if your changes have come through:

jekyll serve

Push your changes:

git push

Leave no evidence of the crime by deleting the newtheme branch.

git branch -d newtheme

Credits

This solution is adapted from Daniel Pelsmaekerwith's answer on StackOverflow to work with the latest versions of Git, Bundler and Jekyll.

Top comments (1)

Collapse
 
nurandi profile image
Nur Andi Setiabudi

Hi, thanks for the article.
However, I stuck at this line

git merge -s ours master --allow-unrelated-histories
Merge with strategy ours failed.

Whats wrong?