Skip to content

Instantly share code, notes, and snippets.

@amitkaps
Last active January 21, 2019 13:23
Show Gist options
  • Save amitkaps/646be08862050b283b52681b20cc28ba to your computer and use it in GitHub Desktop.
Save amitkaps/646be08862050b283b52681b20cc28ba to your computer and use it in GitHub Desktop.
Keeping gh-pages and website/_site folder in sync for Jekyll

Keeping gh-pages in sync with master for Jekyll sites

You have one single repo (master) in which you have both project code (project) and the project website (website) which you want to push to gh-page. The directory structure looks like this.

-- project
	    |-- website 
	    |       |-- _layouts
	    |       |-- _includes
	    |       |-- _posts
	    |       |-- _site
	    |       |-- assets
	    |       |-- index.md
	    |
	    |-- files01
	    |-- files02
	    |-- files03
	    |-- ...

You are on the master tree and in the project root folder. First build the site using Jekyll

cd website
jekyll build
cd ..

You want to commit these changes to the master

git add website/_site/*
git commit -m "Site Update"

Now you want to just deploy the built static site. So you want to push contents of the website/_site/ folder into root directory of gh-pages.

git subtree split --prefix website/_site/ -b gh-pages
git push -f origin gh-pages:gh-pages
git branch -D gh-pages

Or if you want to do with single line, you can do.

git push -f origin `git subtree split --prefix website/_site/ master`:gh-pages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment