20

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.

backspaces
  • 3,802
  • 6
  • 34
  • 58
  • 2
    There are ways to synchronize a *subdirectory* of your master branch with the `gh-pages` branch, i.e. the contents of that subdirectory will define what the `gh-pages` branch looks like, cf. http://www.damian.oquanta.info/posts/one-line-deployment-of-your-site-to-gh-pages.html. Would that help? – krlmlr Dec 05 '13 at 22:38
  • 1
    Using [GitHub for Mac](http://mac.github.com/) or [GitHub for Windows](http://windows.github.com/) is another option that makes performing branch merges and syncs with GitHub.com very simple. – Joel Glovier Dec 07 '13 at 14:45
  • 1
    Just to be clear: I've been able to maintain a local gh-pages branch with the lovely simple checkout/merge/push method. This correctly keeps the gh-pages the only branch with the 5 website files and the master clean of them. The koan is how to, after creating the single edit/commit/push needed to get started, to maintain the gh-pages on github *only* .. no more messing with the local gh-pages branch. – backspaces Dec 07 '13 at 18:15

4 Answers4

31

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
stellarhopper
  • 660
  • 5
  • 10
  • 1
    as i mentioned, this would also merge anything else on master into gh-pages. often time in github projects, gh-pages lives on the same repo as the real project and is just the associated site but has none of the associated source code as the project itself. just fyi, but i believe this is what needs to be done. – Jed Schneider Dec 06 '13 at 00:48
  • 3
    So amazing! Other sites, ranked on top on Google, said to do some garbage "git rebase master" from the gh-pages branch and all it caused was conflicts and problems. Thanks so much! – aaron-coding Nov 14 '14 at 18:20
  • 1
    Change `git merge master` to `git rebase master` in case only cloning the master completely the same – eQ19 Mar 27 '16 at 16:45
12

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.

Jed Schneider
  • 14,085
  • 4
  • 35
  • 46
  • 5
    I think onto = replace, as that is what `git push -f origin master:gh-pages` will do – stellarhopper Dec 06 '13 at 00:45
  • 1
    As said above: into: add the files to the gh-pages branch while "onto" means replace the entire gh-pages branch with the master. Definitely not desired! – backspaces Dec 07 '13 at 18:21
2

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.

jamie
  • 690
  • 7
  • 18
  • 1
    The OP had already mentioned that they've read [that link](http://oli.jp/2011/github-pages-workflow/). – Dan Dascalescu Jun 04 '15 at 11:59
  • 2
    @DanDascalescu fair enough - must have been sleeping on that, but I did add the part of the paul irish endorsement;) – jamie Jun 04 '15 at 20:59
1

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.

Eliran Malka
  • 15,821
  • 6
  • 77
  • 100