Reputation: 3520
I am using jekyll to publish a static site directly on gh-pages branch in Github. The issue I have is that every time I run
$ jekyll --no-auto /Users/khinester/Sites/tzm/
this overwrites the .git directory and I have to recreate this:
$ git init-db
$ git add remote ..
$ git add .
$ git commit -a -m 'message'
$ git branch gh-pages && git checkout gh-pages
etc..
$ git push -f github gh-pages
basically i have the master branch containing the files needed to generate the blog and gh-pages branch which displays the actual blog.
and also note that i have to force push this.
it will be nice to have also be able to version control the updates!
i have read the https://github.com/mojombo/jekyll/wiki/Deployment but this seems has more steps then what i do now.
is there a better way to do this or have i missing something.
Upvotes: 4
Views: 2862
Reputation: 5644
I use the following shell script for committing a Hakyll generated site
(in directory _site
) to the gh-pages
branch. The script:
master
or whatever branch you're on..git
directory because... it isn't there!gh-pages
branch, so you don't need to force push.Code follows; update paths as necessary
export GIT_INDEX_FILE=$PWD/.git/index-deploy
export GIT_WORK_TREE=$PWD/_site
REF=refs/heads/gh-pages
git read-tree "$REF"
git add --all --intent-to-add
git diff --quiet && exit
git add --all
TREE=$(git write-tree)
COMMIT=$(git commit-tree "$TREE" -p "$REF" -m "snapshot $(date '+%y-%m-%d %H:%M')")
git update-ref "$REF" "$COMMIT"
Upvotes: 0
Reputation: 10601
Jekyll has a config array called keep_files
. Everything in that array will be kept when Jekyll rebuilds the site.
Here's where it was added: https://github.com/mojombo/jekyll/pull/630. Searching the issues for keep_files
will reveal more of its black magic.
.git and .svn files are added to keep_files
by default so this shouldn't be a problem anymore.
Upvotes: 1
Reputation: 20431
I used Steven Penny's script to write this one, which out of the box is for Project Pages, not User Pages.
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR
SELF=`basename $0`
SOURCE_BRANCH="master"
DEST_BRANCH="gh-pages"
TMP_DIR="tmp"
git checkout $SOURCE_BRANCH
jekyll build -d $TMP_DIR
git checkout $DEST_BRANCH
# This will remove previous files, which we may not want (e.g. CNAME)
# git rm -qr .
cp -r $TMP_DIR/. .
# Delete this script from the output
rm ./$SELF
rm -r $TMP_DIR
git add -A
git commit -m "Published updates"
# May not want to push straight away
# git push origin master
git checkout $SOURCE_BRANCH
Upvotes: 0