Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for One command deploy with GitHub Pages
nervewax
nervewax

Posted on • Originally published atnervewax.com on

     

One command deploy with GitHub Pages

Cover image by the magnificentAndre Wallin

One of the caveats ofGitHub Pages is that it won’t automatically build your site if you’re not using the GitHub Pages Jekyll gem. On top of this, you can’t use any Jekyll plugins that aren’tsupported by GitHub Pages.

That being said, GitHub will deploycompiled code for you, either from the/docs folder, agh-pages branch or from themaster branch.[ref]

The solution I’m using right now means still I’m able to run my build process locally and auto-deploy with a single command.

So for this to work, I’ve set up two branches for my site:

  • master contains my Jekyll compiled_site/ folder, which GitHub will deploy each time it’s pushed.
    • .nojekyll should be added to this branch so GitHub doesn’t attempt to compile it.
  • sources contains the full repo, with the Jekyll source files.
    • This method could work with any static site generator.
    • _site/ should be added to the .gitignore on this branch, so you don’t commit the changes in there.

I’ve written a simplenpm shell script that runs withnpm deploy, which is essentially an alias for the following string of commands:

bundle exec jekyll build &&cd _site/ &&git add . &&timestamp=$(date \"+%s\") &&git commit -m \"automated deployment $timestamp\" &&git push origin master &&cd ..

Each time I want to deploy:

  1. Thejekyll build command compiles and builds my static site inside the_site/ folder.
  2. We then change directories to_site/, which has a .git config, set to themaster branch of the repo.
  3. The script then commits all changes (+ timestamp), pushes master and returns to my source folder.

That’s it! So now, once I’ve made changes to my site or content, I can still have my site built and deployed with a single command.

Further reading

Moving from Ghost CMS to Jekyll
GitHub Pages Basics
Official Jekyll Docs

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

(ノ ̄ー ̄)ノ
  • Joined

More fromnervewax

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp