jbryer jbryer - 1 year ago 69
Git Question

Using Tower to manage a repository and gh-page branch in separate directories

This seems like a simple thing, but cannot find the solution online. First, I know I can probably do this on the Terminal, but I would prefer to do this with Tower. Not all of my colleagues will use the Terminal. I have a repository (https://github.com/jbryer/psabook/) and I would like to use Github pages with it. I want the master branch to track the source (mostly markdown files). I build a website from those files and would like to publish that to the gh-pages branch. Can I have that as a subdirectory of my repository be tracked only for that branch?

Here's what I have tried from this post: http://blog.blindgaenger.net/generate_github_pages_in_a_submodule.html

I create a repository called psabook from Github.com. Then do the following from the command line (on a Mac if it matters):

mkdir foobar
cd foobar
git init
touch README
git add README
git commit -m "initial commit"
git remote add origin git@github.com:jbryer/psabook.git
git push origin master
git symbolic-ref HEAD refs/heads/gh-pages
rm .git/index
git clean -fdx
echo "Hello PSA Book" > index.html
git add .
git commit -a -m "first gh-page"
git push origin gh-pages
git checkout master
git submodule add -b gh-pages git@github.com:jbryer/psabook.git _site

The output was:

Cloning into '_site'...
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 6 (delta 0)
Receiving objects: 100% (6/6), done.
Checking connectivity... done.


git status


On branc master
Changes to be committed:
(use "git reset HEADE <file>..." to unstage)

new file: .gitmodules
new file: _site


git commit -m "added gh-pages as submodule"
git push

It is this command that I get an error (note that I had to escape the parens too):

git submodule init

Submodule '_site' (git@github.com:jbryer/psagook.git) registered for path '_site'

This is the error I get:

error: pathspec 'Submodule' did not match any file(s) known to git.
error: pathspec '(git@github.com:jbryer/psabook.git)' did not match any file(s) known to git.
error: pathspec 'registered' did not match any file(s) known to git.
error: pathspec 'for' did not match any file(s) known to git.
error: pathspec 'path' did not match any file(s) known to git.
Did you forget to 'git add'?

Answer Source

You can see both content (master and gh-branch) from the master branch.

You would need for that to declare your gh-branch as a submodule(!) in your master branch.
That way, when you are in your master branch, the gh-branch is displayed as a sub-folder.

Once that setup is done (in command line), you can manage everything from Tower.

See "What's the easiest way to deploy a folder to a branch in git?" for the submodule setup.

Each modification in gh-branch would then need to be committed, and you would need to go back in the main folder to commit (again), in order to record the gitlink (special entry mode 160000).
That way, each version of the master branch knows which version of the gh-branch it is supposed to work with.

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.

So this is easier now: now need for two branches, you can do everything in one.