backspaces
backspaces

Reputation: 3942

push local master *into* gh-pages branch on github

I created a simple gh-pages branch on github and in my local repo. I used the auto page generator to create the 5 files it uses: images javascripts stylesheets index.html params.json

I pulled this to my local repo and added js-markdown-extra.js to javascripts, and edited index.html to replace the "content" section with the compiled README.md created by the markdown library.

Putting in a dummy README.md showed it to work perfectly.

I want to then simply push my local master into (not onto) the remote gh-pages branch, without modifying the 5 website files.

I haven't found a way to do this. I was told via http://oli.jp/2011/github-pages-workflow/ that this would work: git push -f origin master:gh-pages

I tried this on a test repo and it failed, resulting in a 404 (pushing the local gh-pages made for the markdown trick fixed that)

So is there a way to push master into, as a subset of, gh-pages?

Failing that, is there a simple way to merge the master into gh-pages locally without deleting the 5 website files?

I know how to "mirror" all this stuff so the 5 files would be in the repo but I'd like to avoid that clutter.

Upvotes: 21

Views: 29367

Answers (4)

Eliran Malka
Eliran Malka

Reputation: 16263

as an alternative approach, how about using a git subtree to serve as your gh-pages branch?

git checkout master
git subtree push --prefix . origin gh-pages

according to the git-subtree docs on the source code:

Subtrees allow subprojects to be included within a subdirectory of the main project, optionally including the subproject's entire history.

in our case, we may be able to alias the same path (the root path; .) as a virtual copy of the master branch (i have not tested it, though).

by the way, i found out about subtrees after encountering this gist, by cobyism.

Upvotes: 1

jamie
jamie

Reputation: 690

Here is a good writeup github pages workflow that I used to understand how to interact between the master and gh-pages branches.

paul irish from google recommended it in the comments of another article- it had super clear examples.

Upvotes: 2

stellarhopper
stellarhopper

Reputation: 670

From what I understand, you'd have to switch to your local copy of gh-pages. Merge in master, and then push gh-pages

git checkout gh-pages
git merge master
git push origin gh-pages

Upvotes: 32

Jed Schneider
Jed Schneider

Reputation: 14671

If I understand you correctly it seems that you created the dummy Readme and the other files on your local master branch but intended to have them on the gh-pages branch. If thats the case, the safest option is to merge your master branch into the gh-pages branch (assuming you dont have other files on master you would rather not have on the gh-pages branch). The command suggested git push -f origin master:gh-pages will push your local master branch to the gh-pages branch. I'm not really sure what you mean but into vs onto, as branch names are just pointers in git.

Upvotes: 13

Related Questions