ohmybuck

Git Commit to Pages

July 23, 2020

Rough script to handle the same functionality as gh-pages-deploy, but extends the functionality by deploying to a repo thats not the same as the origin.

Rather use gh-pages-deploy if you don’t need the above functionality.

#!/usr/bin/env bash

MAIN_BRANCH=$(git branch --show-current)
GH_PAGES_BRANCH=gh-pages
ORIGIN_GITHUB_PAGES=<github pages repo>
ORIGIN_REPO_URL=<origin repo url>
DIST_DIR=dist

git branch -D $GH_PAGES_BRANCH 2>&1
git checkout --orphan $GH_PAGES_BRANCH

git reset .gitignore
git reset $DIST_DIR

git rm -rf .

cp -r $DIST_DIR/* .
rm -rf $DIST_DIR

git add .

git commit -a -m 'Deployed from $ORIGIN_REPO_URL' --no-verify

git remote add origin-github-pages $ORIGIN_GITHUB_PAGES 2>&1

git push origin-github-pages $GH_PAGES_BRANCH --force --no-verify

git checkout $MAIN_BRANCH

Written by Oliver Smit. I love talking about web technologies, good design practices, optimising productivity, and rapid prototyping of projects. Check out my work on Github