Git Subtrees

January 2014

I've been trying for a while to figure out how it was best to deploy to Github pages. I'd refactored my portfolio probably over a month ago to have a nice Gulp setup and use Angular but I'd grounded to a halt with gulp-gh-pages - either I would run the command and nothing would happen or I'd run into memory issues set in place by Node. Ultimately I found a more elegant solution from cobyism that used Git. Enter gulp-shell and we're off to the races!


    var gulp        = require('gulp');
    var shell       = require('gulp-shell');

    gulp.task('deploy', shell.task([
      'git subtree push --prefix build origin master'
    ]));
    

The Gulp Starter I referenced above splits all of its tasks into separate files which is why I only have one thing in here and I'm requiring gulp again.

After we require gulp we require gulp-shell, which lets us enter bash commands into our task declarations. We then specify the subfolder we want to push (build), the remote (origin), and then the branch (master). I'm defining master, not gh-pages, because the yourUserName.github.io repo works off of master instead of gh-pages.