Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publish Jekyll Site To Git Repository

Tags:

git

jekyll

Every time I run Jekyll it destroys the entire contents of the destination folder. The problem with this is that my destination directory is a small git repo from which I use to push to my actual server. Is there a way to stop Jekyll deleting the Git files so that I don't have to generate the contents then copy them over?

like image 393
James Hughes Avatar asked May 17 '11 06:05

James Hughes


3 Answers

You could have:

  • your git repo elsewhere (i.e. not in the directory affected by a Jekyll deployment)
  • have your script pushing that git repo to your server specify a GIT_WORK_TREE variable with the destination folder as value

In other words, a .git don't have to be necessary in the working tree directory itself.
It can be elsewhere, and your script can refer to the actual working tree through GIT_WORK_TREE or through a --work-tree=<path> option.

If your script is part of the destination directory where Jenkyll copies/erases files, you can do the opposite, and mention where the .git actually is with GIT_DIR variable or with --git-dir=<path> option.

To have new --work-dir as default options to your repo, you can use git-config --add core.worktree ../PATH/, where PATH - path to actual working directory relative to .git.

like image 133
VonC Avatar answered Oct 13 '22 20:10

VonC


Have you had a look at the Deployment section of the Jekyll wiki? - https://github.com/mojombo/jekyll/wiki/Deployment. It clearly explains Jekyll deployment steps.

And why are you pushing from the destination? That is bad! Push it from some other clone.

like image 32
manojlds Avatar answered Oct 13 '22 19:10

manojlds


I also want this setup. Found this pull request to fix Jekyll, making it not delete the .git dir: https://github.com/mojombo/jekyll/pull/337

Read my comment there, as:

  1. the fix is actually slightly broken (make it .git not .git$)
  2. I believe a better solution would be to have this as a configuration variable, to handle other files like .svn.

Anyway, my Jekyll line now reads: dest_files << file unless file =~ /\/\.{1,2}$/ || file =~/\/\.git/

Works great! I'm even using octopress (just change your deploy_dir to be public) and comment out the following lines in Rakefile:

    #  (Dir["#{deploy_dir}/*"]).each { |f| rm_rf(f) }
    #  Rake::Task[:copydot].invoke(public_dir, deploy_dir)
    #  puts "\n## copying #{public_dir} to #{deploy_dir}"
    #  cp_r "#{public_dir}/.", deploy_dir

Now your public dir (instead of _deploy dir) can be your github repo to publish your site (submodule of a branch or my parent repo in my case)

Seems senseless to have public and _deploy with octopress, but I'm happy to hear other reasons why to split public and _deploy dirs - besides Jekyll deleting the .git dir. (I read through the full commit history of octopress, but couldn't find any explanation for why its done this way)

like image 37
Mike Schroll Avatar answered Oct 13 '22 21:10

Mike Schroll