Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Publish Single Directories to Another Branch
Ryan Palo
Ryan Palo

Posted on • Edited on • Originally published atassertnotmagic.com

     

Publish Single Directories to Another Branch

Quick Tip!

Let's say that you're just like me. You've been working on a web project: HTML, CSS, and maybe some JavaScript. You're done and you're ready to show the world your project, so you want to get it built, compiled, minified, and put it somewhere. But how?git subtree. I'll show you. One command.

Also, did you see the cover image? Subtree? HA!

Let's assume you've got a project laid out like this:

my-dope-project|- README.md|- src|   |- index.html|   |- css|       |- styles.sass|   |- js|       |- main.js|       |- helper.js|- dist|- webpack.config.js|- package.json|- .gitignore|- node_modules    |- OMG so much stuff
Enter fullscreen modeExit fullscreen mode

Or something. I don't know your life. So you build your site with annpm run build. Now yourdist directory is full of your beautiful bundled new site. So how do you put it up somewhere?

1. Make sure the dist folder is actually checked into your repo.

Get it out of your.gitignore andadd/commit/push it.

2. Use the Subtree, Luke (and/or Leia).

$git subtree push--prefix dist origin gh-pages
Enter fullscreen modeExit fullscreen mode

Here,dist is the directory subtree you want to publish.origin is the remote repo you're pushing to.gh-pages is the name of the remote branch you want to push to.

Then go to your GitHub and into your repo settings.

GitHub Pages Settings

Set the branch that you created to be the public branch. And that's it! Head to<your-username>.github.io/<repo-name> and do your happy dance!

I know that there are about a thousand ways you could skin this particular cat and they all have their pro's and con's. I just really wanted to share this particular approach because I thought it was neat. Happy coding!


Originally published onassert_not magic?

Top comments(2)

Subscribe
pic
Create template

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

Dismiss
CollapseExpand
 
nektro profile image
Meghan (she/her)
24. Local trans witch who prefers to do magic with a keyboard. she/her. Currently hacking away at making the Web less centralized.
  • Email
  • Location
    Massachusetts, USA
  • Education
    B.S. CS @ UMass Dartmouth
  • Work
    unicycle.co
  • Joined

Awesome command, had no idea about this before!

Side note: specifically to solve the problem of posting to GitHub Pages, if you renamedist todocs then the site will publish in the same way automagically. Not the most aesthetically pleasing name for yourdist folder but you can always describe the discrepancy in youractual docs haha

CollapseExpand
 
pmcgowan profile image
p-mcgowan
418 bio is a teapot
  • Joined

Random that I saw this today - I just found out about this yesterday when I wanted to keep the API and front-end in the same repo (don't ask). It's a decent alternative to submodules, but just be advised it replays your subtree history over your original refs, so it may get messy.

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

Ryan is an engineer in the Sacramento Area with a focus in Python, Ruby, and Rust. Bash/Python Exercism mentor. Coding, physics, calculus, music, woodworking. Looking for work!
  • Location
    Elk Grove, CA
  • Education
    M.S.C.S. Lewis University, B.S.M.E. Cal Poly (SLO)
  • Work
    Currently Job Hunting
  • Joined

More fromRyan Palo

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