Jiew Meng
Jiew Meng

Reputation: 88367

GitHub pages for personal site. How to deploy a folder

If I am using GitHub pages for my personal site, how should manage my source files? I have a simple setup which works.

But I understand I can't using Jekyll plugins with GitHub pages. If I want to use Grunt for example to optimise my images, for a usual app/site, it will produce output in say a dist/public folder, which I will then deploy. But I want to still use GitHub to manage my source files, how should I do it?

Upvotes: 3

Views: 1153

Answers (1)

David Jacquel
David Jacquel

Reputation: 52829

Depending of repository kind your using, a User/Organization (UO) site or a Project site (P), sources and pages will be versionned in :

  • User/Organization - sources : sources, pages: master
  • Project - sources : master, pages: gh-pages

Note: The pages branch is mandatory, but the sources branch name can be changed.

Setup

  • Initialize an empty github repository : github.com/userName.github.io for UO or github.com/repositoryName for P

Locally, initialize your local repository :

  • Go to source folder cd /home/username/www/yoursite or anything you want
  • git init
  • git remote add origin [email protected]:userName/userName.github.io.git (UO) or git remote add origin [email protected]:userName/repositoryName.git (P)
  • git checkout -b sources (UO) or git checkout master (P)
  • in your .gitignore add your dist/public. As you are currently on master we will ignore it an version it in an other branch
  • git add -A
  • git commit -m "base sources". You now have committed your sources.
  • git push origin sources (UO) or git push origin master (P) push your sources in the appropriate branch
  • cd dist/public
  • touch .nojekyll, this file tells gh-pages that there is no need to build a Jekyll site
  • git init
  • git remote add origin [email protected]:userName/userName.github.io.git (UO) or git remote add origin [email protected]:userName/repositoryName.git (P)
  • git checkout master (UO) or git checkout -b gh-pages (P) put this repository on the appropriate branch
  • your grunt task here
  • git add -A
  • git commit -m "first build" commit your site code
  • git push origin master (UO) or git push origin gh-pages (P)

You now have pushed your code and pages in two different branches. They will now be pushed depending on where you are :

pushing sources

  • cd yourWorkingDirestory
  • git add -A
  • git commit -m "your commit message"
  • git push origin sources (UO) or git push origin master (P)

pushing pages

  • cd yourWorkingDirestory/dist/public
  • git add -A
  • git commit -m "your commit message"
  • git push origin master (UO) or git push origin gh-pages (P)

Upvotes: 5

Related Questions