Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I push jekyll _site directory to gh-pages branch, and leave the source in master?

I have a basic jekyll site consisting of pages (not posts) but, because I wanted to sort the pages when I listed them, I had to use the Jekyll-Sort plugin (kinda weird sorting pages is not built in to jekyll).

Because I'm using a plugin, I can't leverage GitHub's auto jekylling. So I'd like to push the source code of the project to the master branch and just the _site directory to the gh-pages branch.

I can't figure out how to do this - I tried adding a git repo inside the _site directory to push that to gh-pages but every time I run jekyll it erases that entire directory and I lose the .git folder.

Any suggestions? Or a way to natively sort?

like image 769
Tobias Fünke Avatar asked Jul 24 '13 13:07

Tobias Fünke


People also ask

How do I push master to GH page?

The command suggested git push -f origin master:gh-pages will push your local master branch to the gh-pages branch.

How does GitHub Pages work with Jekyll?

Your site is automatically generated by GitHub Pages when you push your source files. Note that GitHub Pages works equally well for regular HTML content, simply because Jekyll treats files without front matter as static assets. So if you only need to push generated HTML, you're good to go without any further setup.


1 Answers

A less painful solution:

  1. Checkout your branch, where your build-source is located (maybe src, or master)
  2. (Optional: Add _site to your .gitconfig, so it get's ignored, if not already done)
  3. Remove all content of the _site directory:

    $ rm -r _site/*

  4. Clone your repo's gh-pages branch into the _site directory:

    $ git clone -b gh-pages `git config remote.origin.url` _site

Final steps: Just let jekyll build, do commit & push:

$ jekyll build,

cd into _site:

$ cd _site,

target all files for commit:

$ git add -A,

commit them:

git commit -am 'Yeah. Built from subdir'

and push your site to GitHub-Pages:

git push.

like image 102
Sebastian Blei Avatar answered Oct 03 '22 21:10

Sebastian Blei