Way to serve a "public" folder in github pages - github

I have personal blog in github repo myname.github.io, i generates my site contents using Cabin site generator which generate build files in public folder. I wanted to serve the contents from public folder for Github pages. But it is always looking at the root folder.
Is there any option to tell Github to serve contents from public folder, not from root folder?

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).
Make sure git knows about your subtree (the subfolder with your site).
git add dist && git commit -m "Initial dist subtree commit"
Use subtree push to send it to the gh-pages branch on GitHub.
git subtree push --prefix dist origin gh-pages
Source: https://gist.github.com/cobyism/4730490
Go to the settings of the project and set the gh-pages as the branch
for the website

Related

Adding github pages to all subfolders?

I have a repository in github which will house all of my web development assignments in separate sub-folders like :
VishnuVelukutty/ CourseraWebdevAssignment (master)/ module2-assignment (subfolder)
So the master branch has gh-pages and I want to add the gh-page to all sub-folders (Assignment1,2,3 .....) independently so that they work independently when the specific module-link is opened
Is it possible to apply gh-pages to a subfolder ? or do I have create independent repo for each module ?
I have not initiated .gitignore, static site, readme nor theme and reffered to this post by cobyism and chrisjacob but i didn't get it working
Here is my github account to see if there any errors in setting up
For reference of the images here is the git link
First, make sure to create a gh-pages branch, add at least one commit in it and push it to your GitHub repository.
Then, yes, you can add that gh-pages branch content as a subfolder of your current repository, in the master branch, using git submodule.
(unless, as explained here, you chose the master branch itself as source for GitHub Pages)
git checkout master
git submodule add -b gh-pages -- /remote/url/of/your/own/repo gh-pages
git commit -m "Add gh-pages branch as submodule"
git push
You will have a gh-pages subfolder, that you can update at any time with:
git submodule update --remote

index.html in github repo not opening

I am trying to see a static html file. My github url is anuragasaurus.github.io and my repo name is js-playground, it contains a index.html file.
I am trying to open anuragasaurus.github.io/js-playground/index.html but it's showing 404.
Can anybody tell me how can I access index.html file in my js-playground repo.
In order to view your project files as static webpage, you should store your files not in default master branch but in gh-pages branch.
You can create this branch using multiple methods but in order to find out the convenient one, you can use this GitHub Pages link.
Basically, let's assume that you already have master branch. If you are using git command line tool, you can do that with these steps:
cd your-project-folder
git checkout -b gh-pages (it will create new branch and switch to it)
git push origin gh-pages (it will create new branch on GitHub repo and push the existing files to it)

host github pages from /dist folder in master branch

I was trying to publish my -username-.github.io repository to github pages but my index.html is inside dist folder.
I cannot use git subtree push --prefix dist origin gh-pages because this is meant for project pages, not user/org pages.
All I want is, github to treat dist as root directory for hosting user/org page. Please help.Thanks
PS: I don't want to do redirection hack.
Configuring a publishing source for GitHub Pages (very limited)
While you can select a folder as the source for gh-pages, you can only do so for the /docs directory at the parent level, and you still have to actually commit the built files in order to do so, which means you'll have to override the .gitignore and commit them twice
Automated Deploy Scripts
If you're using npm, there are a couple packages that handle publishing sub-directories to gh-pages. Install with option --save-dev to add it to your devDependencies:
push-dir
# install
$ npm install push-dir --save-dev
# usage
$ push-dir --dir=dist --branch=gh-pages
gh-pages
# install
$ npm install gh-pages --save-dev
# usage
$ gh-pages -d dist
In either case, if get a command line tool working for you and get it configured with the right options, you can alias it in your package.json like this:
"scripts": {
"deploy": "npm run build && gh-pages -d dist"
}
Further Reading:
Deploying a subfolder to GitHub Pages
Deploy Vue to GitHub pages-the easy way!
You can't do it this way.
GitHub pages can be hosted from either:
the / folder in the master branch
the / folder in the gh-pages branch
the /docs folder in the master branch
But the user pages must be built from the / folder in the master branch.
TIP
Code on another branch than the master. After every push to this branch, build it in any CI/CD tool and push it back to the master branch.
If like me you would prefer to upload to github pages using subtree's in git you can use something like the code below.
git subtree push --prefix dist origin gh-pages

Does github honour Jekyll's "source" variable?

In an attempt to make my workflow a bit neater, I came across the source tag, which allows me to host my "dev work" in a separate folder than my _site.
This is awesome, but it does not appear to be honoured by Github pages? I feel like I am doing something wrong though, so just wanted to check. I couldn't find much about it online.
In this case, I don't explicitly need github to do it, but it would be great to have this consistent workflow for projects that do rely on github pages.
Thanks!
GH Pages overrides the source setting in the Jekyll config file:
https://help.github.com/articles/troubleshooting-github-pages-build-failures#source-setting
http://jekyllrb.com/docs/github-pages/#project-pages
You don't need to change source or destination parameters to version them separately. You can just version them in two different branches from the same repository.
Why versioning in different branches ?
If you need some plugins (generator, tag, ...) or build tasks (gulp, grunt, ...) that will not run on gh-pages, you will have to publish your Jekyll sources in a branch and your build results in a separate branch.
For a User / Organization site, it will be master for the site build, and sources (or any name you like) for the code. A User / Organization site will be versioned at github.com/userName/userName.github.io and hosted at http://userName.github.io (or with a custom domain)
For a Project site, it will be gh-pages for the site build, and master (or any name you like) for the code.
A Project site will be versioned at github.com/userName/projectName and hosted at http://userName.github.io/projectName.
Steps for User\Organization site
create a repository on github (eg: https://github.com/userName/userName.github.io)
go to command line and cd pathTo/yourJekyllSource
git init
git remote add origin git#github.com:userName/userName.github.io.git
jekyll new . creates your code base
in _config.yml, set the baseurl parameter to baseurl: ''
in .gitignore add _site, it will be versioned in the gh-pages branch
jekyll build will create the _site destination folder and build site into it.
git checkout -b sources
git add -A && git commit -m "jekyll base sources" commit your source code
git push origin sources push your sources in the sources branch
cd _site
touch .nojekyll, this file tells gh-pages that there is no need to process files
git init
git remote add origin git#github.com:userName/userName.github.io.git
git checkout master
git add -A && git commit -m "jekyll first build" commit your site code
git push origin master
And your good to go !
Your deploy can be made like this :
cd pathTo/yourJekyllSource
jekyll build
git add -A
git commit -m "your commit message"
cd _site
git add -A
git commit -m "your commit message"
Steps for a Project site are described here and I've made an automation Rakefile, it can do everything for you from setup to deploy.
Enjoy !

Github Showing Parent Directories

I have a website I'm developing, it's github is https://github.com/samclark2015/Project-Emerald. I have the repo under my user folder in a subdirectory. Now when I push the site to github, it updates the tree as Sites/Project Emerald/... I need the contents of the project emerald folder in the root of my github repo. How can I change the root of my repo on my PC?
Since you just did your first commit in your GitHub repo, the easiest way would be to:
delete your local .git directory you have under 'Site'
recreate your repo locally, and force push it:
That would give:
# in Site/Project-Emerald
git init .
git add remote origin https://samclark2015#github.com/samclark2015/Project-Emerald.git
git add .
git commit -m "first commit, again"
git push -force origin master
You would then see in your GitHub repo directly:
PHP
SpryAssets
pictures
README
config.inc
...
Other alternatives are mentioned in "My Git repository is in the wrong root directory. Can I move it? (../ instead of ./)"