December 2008

Copy Folders to a Branch

GitHub Pages is pretty cool. However, what do you do when you already got your website/docs/whatever in your master-branch? If you checkout the gh-pages branch, the folder disappears and you actually have to copy it to another place before you copy it to your new branch.

If it’s an automatically generated folder, it’s a bit easier, but still quite a few commands:

rake generate_some_docs
git checkout gh-pages
git add .
git commit
git push

It’s even harder if you haven’t created the gh-pages branch yet.

Grancher!

Okey, enter Grancher (yeah, I know, lame name):

# Install:
system('sudo gem install grancher')

# Create a Rakefile:
require 'grancher/task'
Grancher::Task.new do |g|
  g.branch = 'gh-pages'
  g.push_to = 'origin' # automatically push too
  
  g.directory 'website'
end

Do a rake publish and the folder will be copied to the gh-pages branch, committed and pushed. Easy peasy!

Have a look at the documentation which isn’t actually perfect, but should be enough to get started.

Oh, and it’s just a few hours old, so bugs will probably bite you! When they do, please report it at lighthouse.