Skip to content

Instantly share code, notes, and snippets.

@emerywebster
Last active March 28, 2021 15:42
Show Gist options
  • Save emerywebster/775efabecc9380e9c8b95334e7c1068d to your computer and use it in GitHub Desktop.
Save emerywebster/775efabecc9380e9c8b95334e7c1068d to your computer and use it in GitHub Desktop.
function gh-pages-deploy () {
directory=_site
current_branch=$(git rev-parse --abbrev-ref HEAD)
deploy_branch=gh-pages
build_command() {
bundle exec jekyll build
}
if [[ "$current_branch" != "main" ]]; then
echo "\033[0;32mAborting - switch to 'main' branch\033[0m";
else
echo -e "\033[0;32mDeleting old content...\033[0m"
rm -rf $directory
echo -e "\033[0;32mChecking out $deploy_branch....\033[0m"
git worktree add $directory $deploy_branch
echo -e "\033[0;32mGenerating site...\033[0m"
build_command
echo -e "\033[0;32mDeploying $deploy_branch branch...\033[0m"
cd $directory &&
git add --all &&
git commit -m "Deploy updates" &&
git push origin $deploy_branch
echo -e "\033[0;32mCleaning up...\033[0m"
cd ..
git worktree remove $directory
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment