Skip to content

Instantly share code, notes, and snippets.

@georgegach
Forked from SangsooNam/gh-pages-deploy.sh
Last active August 21, 2022 07:42
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save georgegach/6dd6a15e7294045258079d161264bdbc to your computer and use it in GitHub Desktop.
Save georgegach/6dd6a15e7294045258079d161264bdbc to your computer and use it in GitHub Desktop.
Script to deploy a target directory to `gh-pages` branch and force server-side cache to update
#!/bin/bash
directory=_site
branch=gh-pages
build_command() {
jekyll build
}
echo -e "\033[0;32mDeleting existing $branch...\033[0m"
git push origin --delete $branch
git branch -D $branch
echo -e "\033[0;32mSetting up new $branch branch\033[0m"
git checkout --orphan $branch
git reset --hard
git commit --allow-empty -m "Init"
git checkout master
echo -e "\033[0;32mDeleting old content...\033[0m"
rm -rf $directory
echo -e "\033[0;32mChecking out $branch....\033[0m"
git worktree add $directory $branch
echo -e "\033[0;32mGenerating site...\033[0m"
build_command
echo -e "\033[0;32mDeploying $branch branch...\033[0m"
cd $directory &&
git add --all &&
git commit -m "Deploy updates" &&
git push origin $branch
echo -e "\033[0;32mCleaning up...\033[0m"
git worktree remove $directory
@georgegach
Copy link
Author

georgegach commented Jul 20, 2019

This script is a fork of an excellent guide by @sangsoonam and tackles the problem of Github's server-side caching that sometimes takes hours to update.

Currently, the only workable solution is to delete the gh-pages branch entirely that will force the cache to be updated (lines 8-16).

In my limited experience update may take from 20 seconds up to 5 minutes. Triggering the change from Settings (by switching to master and back to gh-pages) seemingly helps. Will update this comment on any related findings in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment