user4616791
user4616791

Reputation:

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.

Upvotes: 3

Views: 3331

Answers (3)

mikeym
mikeym

Reputation: 6331

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.

Upvotes: 3

talves
talves

Reputation: 14353

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.

Upvotes: 2

maxheld
maxheld

Reputation: 4273

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.

Upvotes: 0

Related Questions