Does github honour Jekyll's "source" variable? - github

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 !

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

Pushing projects to github

I want to upload a project in git hub and push my project in git hub account?
what does this statement mean:
"We recommend every repository include a README, LICENSE, and .gitignore."
Can someone suggest how to proceed after this?
Minimal Set of Steps:
Assuming you are working on some terminal.
1) Clone the project
git clone link-to-your-repo
2) Move inside project directory
cd repo-name
3) Add files
For adding all files use
git add .
4) Commit files
git commit -m "commit-message"
5) Push files to Github
git push -u origin master
6) If you haven't setup SSH keys, it will ask for credentials. Enter your credentials.
Voila!
Github is recommending to include some files, but these are not required to push your project to a repository.
The three files are README.md, a license and a .gitignore file.
The README.md file is what you will see when viewing the repo and it can contain anything, but a good template of what to include can be viewed here.
The license is what specifies how/if the code can be used by other people and any rules that will govern that use.
The gitignore file specifies what files git will ignore from including in the repository. A good description of this file and how to use it can be found here.
These are all optional so after including them/not including them you can just push your code the repository as usual:
git add .
git commit -m "initial commit'
git remote add origin <your repo url here>
git push -u origin master

How do I configure GitHub to use non-supported Jekyll site plugins?

I just created a great gallery for my Jekyll blog which builds perfectly on my localhost:4000. However, GitHub pages doesn't support the Jekyll Gallery Generator plug-in I am using: https://github.com/ggreer/jekyll-gallery-generator
I read about the alternative method of hosting Jekyll on a traditional host using FTP (uploading the _site directory) http://jekyllrb.com/docs/deployment-methods/ However, rather than reconfigure my entire site and hosting, It would be great if GitHub Pages could be used somehow even though I'm using a non-supported plugin.
What is a workaround for this?
Depending if you deal with a User/Organization (UO) site or a Project site (P), do :
from your working folder git init
git remote add origin git#github.com:userName/userName.github.io.git (UO) or git remote add origin git#github.com:userName/repositoryName.git (P)
jekyll new . creates your code base
in _config.yml, set the baseurl parameter to baseurl: '' (UO) or baseurl: '/repositoryName' (P)
in .gitignore add _site, it will be versioned in the other branch
jekyll build will create the destination folder and build site.
git checkout -b sources (UO) or git checkout master (P)
git add -A
git commit -m "jekyll base sources" commit your source code
git push origin sources (UO) or git push origin master (P) push your sources in the appropriate branch
cd _site
touch .nojekyll, this file tells gh-pages that there is no need to build
git init init the repository
git remote add origin git#github.com:userName/userName.github.io.git (UO) or git remote add origin git#github.com:userName/repositoryName.git (P)
git checkout master (UO) or git checkout -b gh-pages (P) put this repository on the appropriate branch
git add -A
git commit -m "jekyll first build" commit your site code
git push origin master (UO) or git push origin gh-pages (P)
You now have something like Octopress does. Look at their rake file, there are some nice comments inside.
Better way is to configure Travis to automate deployment of jekyll with non-supported plugins. Follow Travis getting started guide to enable Travis for your repo.
Create script/cibuild with the following content
#!/usr/bin/env bash
set -e # halt script on error
bundle exec jekyll build
touch ./_site/.nojekyll # this file tells gh-pages that there is no need to build
Create .travis.yml with the following content (modify as required)
language: ruby
rvm:
- 2.3.3
before_script:
- chmod +x ./script/cibuild # or do this locally and commit
# Assume bundler is being used, therefore
# the `install` step will run `bundle install` by default.
script: ./script/cibuild
# branch whitelist, only for GitHub Pages
branches:
only:
- master
env:
global:
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true # speeds up installation of html-proofer
sudo: false # route your build to the container-based infrastructure for a faster build
deploy:
provider: pages
skip_cleanup: true
keep-history: true
local_dir: _site/ # deploy this directory containing final build
github_token: $GITHUB_API_KEY # Set in travis-ci.org dashboard
on:
branch: master
Deployment steps (after every push):
Build will be created using our custom script script/cibuild in _site directory
_site will be pushed to gh-pages branch.
github pages will serve site as it is without building it again (because of .nojekyll file)
Reference: My repository https://github.com/armujahid/armujahid.me/ is using this method for continuous integration using Travis CI

Middleman and Github pages

I'm trying to create a static site using Middleman. The git repo master has the source files. The static files are generated in the build folder which is in .gitignore. I have a branch gh-pages for Github pages. How do I setup things such that the gh-pages has contents of the build folder of master.
Thanks.
Looks like this gem provides an elegant solution:
middleman-gh-pages
I've started using the same technique as Octopress uses, it works great for Middleman.
Basically I use two git repositories, one inside the root folder and one inside the build folder. The root repository pushes to the develop branch on the GitHub remote and excludes the build directory. The repository inside the build directory pushes to the master (or gh-pages) branch of the same GitHub remote.
To automate the pushing of the new static pages, I use the following Rakefile:
desc "deploy build directory to github pages"
task :deploy do
puts "## Deploying branch to Github Pages "
cp_r ".nojekyll", "build/.nojekyll"
cd "build" do
system "git add ."
system "git add -u"
puts "\n## Commiting: Site updated at #{Time.now.utc}"
message = "Site updated at #{Time.now.utc}"
system "git commit -m \"#{message}\""
puts "\n## Pushing generated website"
system "git push origin master"
puts "\n## Github Pages deploy complete"
end
end
Another good gem is middleman-deploy. After you have installed it and configured everything, you can simply run
$ middleman deploy
and your build directory will be pushed to GitHub pages. You can specify which branch you push to in the config. I also have a blog post here regarding switching from Jekyll to GitHub pages and it talks a little about deployment.
I couldn't find a clean way of doing this. This is a script I've been using:
bundle exec middleman build
mv build /tmp/
git checkout gh-pages
git rm -rf .
cp -r /tmp/build/* .
git add .
git commit -m "Update site"
rm -rf /tmp/build
git push
git checkout master

How to push only specific folders from Master branch to gh-pages branch?

I'm fairly new to github and web development in general. So say I have all of my project files on my Master branch and I want to push only the files needed to make my page run on gh-pages. How would I tell it to only push certain files to the new gh-pages branch? For example, when you use gulp or grunt it makes a folder that is your rendered site for previewing your site. How would I push only the contents from that site folder to gh-pages without adding all of the other unecessary that are on the Master branch?
I've been using Jekyll recently because you can still push all of the files onto gh-pages and it still works. But I have 2 repositories for a lot of my projects. One repository has all of the source files and then the other repository has only the files I need to push a working site onto gh-pages. I want to clean up my github page so it is more organized.
Thank you.
I know this is an old question, but for the benefit of newcomers to Git branches / gh-pages that might stumble across this problem, I found the least complicated way of moving files or folders from a master branch to a gh-pages branch is to do the following.
# First switch to the gh-pages branch
git checkout gh-pages
# Next checkout the specific file you wish to add to the gh-pages branch
git checkout master -- <path/to/file/folders/on/master/branch>
# Perfom the commit
git commit -m "Updated index.html from master"
# And push
git push
Assuming the file(s) you are trying to add to the gh-pages branch exist on the master branch you shouldn't have any problems following the above steps.
If you are using nodejs and npm you can use the gh-pages package from the command line to publish to a gh-pages branch from a specific directory. The gh-pages package has a command line utility.
Installing the package creates a gh-pages command line utility. Run gh-pages --help to see a list of supported options.
Note: You mentioned using Gulp and there is an npm package called gulp-gh-pages that I use successfully to create gulp tasks to put into my deploy workflow.
I believe you're looking for git subtree merge.
The idea of the subtree merge is that you have two projects, and one of the projects maps to a subdirectory of the other one and vice versa.
When you specify a subtree merge, Git is smart enough to figure out that one is a subtree of the other and merge appropriately — it’s pretty amazing.