7

What I want to do: I am using github. I have two branches. Master and gh-pages. I have a unity3d project on my master branch. When I run it, it will generate a webpage. I want to display the contents of the webpage on the gh-pages branch.

I assume this means I have to share a folder between two branches of my repository. That seems nearly impossible.

Is there a right way to do this? My current solution is making two github projects and building from the first into the second. Then, I view the gh-page for the second. That seems very... extraneous. I should be able to do this all with one project.

Zombo
  • 1
  • 62
  • 391
  • 407
tavoe
  • 135
  • 1
  • 8
  • O.o that's a very strange situation... I would have handled the web pages on a different branch from those 2. – Francesco Belladonna Dec 17 '12 at 01:05
  • I don't expect to be doing this for too long. Sooner or later, the game will get its own website, but for now being able to hit build/commit and have it host without any other funny business would be wonderful. – tavoe Dec 17 '12 at 01:19
  • Here's something that works: "git checkout master WebPlayer/WebPlayer.unity3d". Run that from gh-pages and it will pull in the web player. Now, can I automate git to run that script just before I commit gh-pages, every time? – tavoe Dec 17 '12 at 01:34
  • Ok. There's this thing called a git-hook. If I do... something... I can get the above script to run every time I switch to the gh-pages branch. Unfortunately, I have very little idea what that something is. My current plan is to: 1) go into ".git/hooks" and create "post-checkout.bat" (I'm on windows, would bat make sense or is it .txt or .sh?). Then, I put the script in the bat file and, when I switch to gh-pages, it copies over the file I want. Only, it doesn't. Any advise? – tavoe Dec 17 '12 at 02:00
  • 1
    Duplicate of [this question](http://stackoverflow.com/questions/10590156/git-update-the-root-directory-of-a-branch-from-the-subdirectory-of-another/10591668#10591668) – jthill Dec 17 '12 at 02:32

4 Answers4

11

You can just clone your repository again within your working directory structure of the first repository. So locally, you have this folder structure:

project
|- .git/
|- .gitignore
|- (other project related files)
|- deploy/
   |- .git/
   |- (deployed files)

Both project and deploy are cloned repositories of your project; deploy has the gh-pages branch checked out. The outer .gitignore obviously lists deploy/, so the folder is ignored for the project.

Now, when deploying, you publish all the files into the deploy folder, then cd into it, do a git add ., git commit, git push and the generated files are deployed.

Obviously this will not give you an actual relation between your master and the gh-pages branch, but both will live completely independent of each other in the same repository.

poke
  • 369,085
  • 72
  • 557
  • 602
1

This is similar to the Jekyll workflow. Say unity3d content is generated into a folder called foo. Add foo to .gitignore then do this

git checkout master
<run unity3d>
git checkout gh-pages
git rm -qr .
cp -r foo/. .
rm -r foo
git add
git commit

Example

Zombo
  • 1
  • 62
  • 391
  • 407
1

Check out the fantastically awesome gh-pages npm module. With a few lines of code, eg:

var ghpages = require('gh-pages');
var path = require('path');
ghpages.publish(path.join(__dirname, 'dist'), function(err) { ... });

You will be create the gh-pages branch, and push it to github!

In more detail, from the docs:

Calling this function will create a temporary clone of the current repository, create a gh-pages branch if one doesn't already exist, copy over all files from the base path, or only those that match patterns from the optional src configuration, commit all changes, and push to the origin remote.

It is super configurable, and works like a charm for me.

Harlan T Wood
  • 2,064
  • 21
  • 19
0

I wanted to push my doxygen docs from master to gh-pages "easily."

I read similar solutions and my eyes glazed over.

My solution was:

  1. source branch: have the files a .gitignore listed "temporary directory"
  2. change branches to gh-pages (which preserves the .gitignore listed directory)
  3. gh-pages branch: rsync from the temporary directory to the proper directory
  4. gh-pages branch: 'git add -u' the proper location directory
  5. gh-pages branch: 'git commit'

This still requires manually running the update and committing, which might be a good thing if you are posting to the website only from specific builds.

Example (mostly comments) at: https://github.com/nekenyu/libBsdSockets/blob/gh-pages/update_doc.sh

albert
  • 8,285
  • 3
  • 19
  • 32
Jonathan Seng
  • 1,219
  • 7
  • 20