Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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