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?
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 git@github.com:userName/userName.github.io.git
(UO) orgit remote add origin git@github.com:userName/repositoryName.git
(P)git checkout -b sources
(UO) orgit checkout master
(P)- in your .gitignore add your
dist/public
. As you are currently onmaster
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) orgit push origin master
(P) push your sources in the appropriate branchcd dist/public
touch .nojekyll
, this file tells gh-pages that there is no need to build a Jekyll sitegit init
git remote add origin git@github.com:userName/userName.github.io.git
(UO) orgit remote add origin git@github.com:userName/repositoryName.git
(P)git checkout master
(UO) orgit 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 codegit push origin master
(UO) orgit 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) orgit push origin master
(P)
pushing pages
cd yourWorkingDirestory/dist/public
git add -A
git commit -m "your commit message"
git push origin master
(UO) orgit push origin gh-pages
(P)
来源:https://stackoverflow.com/questions/27664282/github-pages-for-personal-site-how-to-deploy-a-folder