1

Here's an interesting experiment with using Git. Think of Github's ‘pages’ feature: I write a program in one branch (e.g. master), and a documentation website is kept in another, entirely unrelated branch (e.g. gh-pages).

I can generate documentation in HTML format from the code in my master-branch, but I want to publish this as part of my documentation website in the gh-pages branch.

How could I intelligently generate my docs from my code in master, move it to my gh-pages branch and commit the changes there? Should I use a post-commit hook or something? Would this be a good idea, or is it utterly foolish?

avdgaag
  • 38,646
  • 7
  • 27
  • 26
  • i think this may be related: http://stackoverflow.com/questions/1425892/how-do-you-merge-two-git-repositories – Eimantas Sep 15 '09 at 18:10
  • @Eimantas: Not really, I think. This is about two branches in the same repository, not two different repositories. – avdgaag Sep 15 '09 at 18:17
  • a pre-tag hook could be done, in order to generate the documentation and publish if on the branch, before reverting to master and apply the tag. But I am not familiar enough with git hooks to see exactly how to do it. – VonC Sep 15 '09 at 18:24

2 Answers2

2

You could 'git stash' your generated files and apply then on the relevant branch

git checkout master
#generate doc
git stash save
git checkout gh-pages
git stash pop

Update August 2016: Simpler GitHub Pages publishing now allows to keep your page files in a subfolder of the same branch (no more gh-pages needed):

Now you can select a source in your repository settings and GitHub Pages will look for your content there.

You can now keep your doc up-to-date with your code in a subfolder of the same branch.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • 1
    I hadn't thought of stashes yet, that looks neat. Would it be possible to automate it, for example a hook that runs before I create a tag or something? – avdgaag Sep 15 '09 at 18:19
1

What would be the advantage of having generated files under version control? And if you insist on this, what would be the advantage of having generating and generated files in the same repository? git's branching support is fantastic, but I am sure it wasn't designed to do what you are trying to do.

innaM
  • 46,211
  • 4
  • 64
  • 85
  • I agree, since this `gh-pages` branch is actually a separate project, not really a branch of the main code base. It would be a hack. Still I'm curious if it can be done. – avdgaag Sep 15 '09 at 18:40
  • The Git repository of Git itself does exactly that (for man pages and stuff) so if they do it it must be right! :) – Bombe Sep 16 '09 at 05:49