34

The documentation of Jekyll tells me, that the _site-directory of a Jekyll site contains the compiled version of the site I have created after running

Jekyll build

Several articles recommend, that I include the _site-directory in my .gitignore-file because "it just contains the compiled version of my site". (that's what some articles recommend. So, I am not sure if I don't understand some concept of Jekyll or some concept of Git.

If the _site-directory contains the compiled version of a site, shouldn't that be the thing that is on the server the provides the final website? I do understand why you put source code on github and what to do with it, but in the case of github pages, Github is not a versioning system but a file hosting system and the file hosting system should host compiled versions of my work to provide it via MyUsername.github.io to users, right?

My question is: shouldn't it be only the _site-directory of my Jekyll website that I deploy to Github because that should be the compiled source code that github provides to users? So, shouldn't I put anything else in the .gitignore-file EXCEPT the _site-directory?

If I got this all wrong: what is the point in compiling my website via

Jekyll build

if I don't use the compiled source code for anything?

1
  • 3
    I think the real confusion here arises from the fact that Github supports Jekyll. If you publishing to Github Pages using any other tool, you'd have to check in _site to see the results. But since Github understands that your code is a Jekyll site, it's doing that compilation on the server. Commented Mar 14, 2016 at 6:36

4 Answers 4

29

Two solutions :

You don't use Jekyll plugins (or only those supported by github pages)

You build your site only if you need to test it locally (jekyll build or jekyll serve). The generated code (in _site) will not be versioned as github pages will generate pages from the sources.

  • Put _site to .gitignore
  • Push you sources to github pages

You use Jekyll plugins

In this case, you need to build locally because Github pages cannot do the job with plugins.

  • Jekyll build locally
  • Put _site to .gitignore
  • commit your sources in one branch
  • commit your _site in another branch

See this post for more explanations.

2
  • Thanks for your reply. I know how to do this, but I don't know why. I have not thought about plugins at all. My only question is, why I should compile anything without using the compiled code for anything? My compiled code will never reach the server (github) if I put it in gitignore. So, what's the point in compiling? Commented Aug 7, 2015 at 7:35
  • 3
    @Otterfinger the key take away here is that you don't need to keep track of _site if you're hosting on GitHub Pages (without plugins), since GitHub Pages automatically builds/generates the site from your source code, So when you visit username.github.io you get the compiled version, auto generated from the source you have in the repo. Commented Aug 8, 2015 at 5:07
7

I think the point where you are confused is that most of the tutorials talk about at least two different repositories.

  1. the source code of your site, this is where you call Jekyll build
  2. the compiled result, this is the one where you put the contents of the _site directory

Then it makes sense to ignore _site in case 1. out of the same reason you normally ignore compilation results: they are not meant to be tracked because they might change between every compilation without changing the source, so you would have to commit after every build although nothing (visible) has changed.

For repository 2. you of course have to update it with the contents of _site from repository 1 after your build.

Having said that you can of course combine 1. and 2. into a single repository by using master for the contents of _site and another branch e.g. source for the project with the Jekyll build files, here ignoring _site and then updating the master branch with the contents of it after changes.

1
  • not sure what the workflow would look like for this. Could you outline the commands involved with generating a new site and committing the site to a separate branch? Commented Aug 24, 2019 at 4:42
2

the _site folder is cleared and all files inside are re-generated upon each "jekyll build". tracking a file that is to be removed seems to serve no useful purposes.

if you are thinking to git push your jekyll site to your github repo as a project page (gh-pages), the _site folder again serves no purposes as the jekyll installation at github will generate the _site for you automatically upon your files upload (git push).

the _site folder is useful only for local preview of your jekyll site (typically to be found at localhost:4000 by default).

0

I believe you might be looking at things the wrong way, It makes sense to ignore _site since every time you jekyll build your _site gets blasted, everything in there gets erased and written again.

So in my own opinion what you would like to push to github is the working directory since it's there where you work and all your changes are being versioned... with the plus of github doing the compiling and automatically building the site.

That being said, I usually keep _site out of my gitignore since I deploy to another hosting service and my deployment framework grabs the github repository and deploys from a particular branch I need the _site to be there.

Not the answer you're looking for? Browse other questions tagged or ask your own question.