Why put the _site-directory of a Jekyll site in .gitignore?

Otterfinger picture Otterfinger · Aug 7, 2015 · Viewed 10.5k times · Source

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?

Answer

David Jacquel picture David Jacquel · Aug 7, 2015

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.