Skip to content

Instantly share code, notes, and snippets.

@hylyh
Last active October 29, 2017 23:51
Show Gist options
  • Save hylyh/bd908b9e4b3236ec1d9c1bcada956553 to your computer and use it in GitHub Desktop.
Save hylyh/bd908b9e4b3236ec1d9c1bcada956553 to your computer and use it in GitHub Desktop.
Build and push subdirectory to gh-pages

One command to build your project and deploy a subdirectory to your gh-pages branch. Originally created by @jkap

Warning: This script force pushes to gh-pages every time, you shouldn't plan on working in that branch if you use this

howto

  • Make sure you already have a gh-pages branch
  • Replace BUILD and BUILDDIR variables with the build command and the directory your web project is built to
  • Make the script executable chmod +x gh-pages-push.sh
  • Run ./gh-pages-push.sh

If you have any working changes when you push, they will still be there after the script finishes.

License: MIT (c) 2017 jenn kaplan and j hayley

#!/bin/sh
# License: MIT (c) 2017 jenn kaplan and j hayley
# Build and push just the build directory to the gh-pages branch
# gh-pages branch must already exist
# Warning: Force pushes to gh-pages every time,
# you shouldn't plan on working in that branch if you use this
set -e
BUILD="pub build"
BUILDDIR="build/web"
$BUILD
git add -f $BUILDDIR
git commit -m "Deploying to gh-pages"
git push origin `git subtree split --prefix $BUILDDIR master`:gh-pages --force
# Roll back the commit we made for the deploy (no working changes will be lost)
git reset HEAD~1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment