1

I want to have a /doc folder in master and easily merge/sync it to the root of a gh-pages branch. What is the easiest way to do this?

NotDan
  • 31,709
  • 36
  • 116
  • 156

2 Answers2

3

One nice trick would be to declare the branch gh-branch as a submodule in your master branch (also more detailed in "How to add a git repo as a submodule of itself?").

That way, when you are in your master branch, you see a folder gh-branch which represents the gh-branch content.

You could then:

  • version doc only in the gh-branch
  • have a symlink doc in your master branch, linked to gh-branch/doc

That way, you maintain the doc/ content only in one place.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
3
#!/bin/sh

# if there's a docbranch tree and it matches master:doc,
# then get out now, there's nothing to do:

current=`git rev-parse -q --verify docbranch:` \
&& test $current = "`git rev-parse -q --verify master:doc`" \
&& exit 0

# update the docbranch ref to a new commit ...    
git update-ref refs/heads/docbranch $(
        # ... which has master:doc, parented on docbranch if that exists yet
        git commit-tree ${current:+-p docbranch} -m "updating" master:doc
)

You can use that as your post-commit hook and chmod +x it, every time you commit anything, if the master doc directory has changed it will commit it to the head of docbranch.

Since the tree's already committed, the only thing this adds is the (~200 byte) commit object itself.

jthill
  • 55,082
  • 5
  • 77
  • 137
  • Nice use of `git commit-tree`. +1 (even if I like my submodule approach too) – VonC Jun 01 '14 at 19:11
  • @VonC Thanks. I've given up recommending submodules unless I see good evidence of a reader because without it, it seems to me folks have a blind spot, no explanation seems to reach them. I think having never used a dvcs before puts repo administration out of their comfort zone, clone is pretty much the limit, so even the easy ops&admin needed for nested-repo administration is too far out. Even the desire for scripting fluency isn't a given here. – jthill Jun 01 '14 at 20:23